Skip to content

Instantly share code, notes, and snippets.

@conikeec
Created April 24, 2020 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conikeec/3286bf9bea9b282502e55a7d87b02d3c to your computer and use it in GitHub Desktop.
Save conikeec/3286bf9bea9b282502e55a7d87b02d3c to your computer and use it in GitHub Desktop.
git clone https://github.com/wangsaisai/spring-boot-example.git
cd spring-boot-example
mvn clean compile package
createCpgAndSp("/Users/chetanconikee/Downloads/spring-boot-example-1.0-SNAPSHOT.jar")
case class Parameter(name : String, parameterType : String)
case class Method(name : String, routeMetaData : List[String], parameters : List[Parameter], returnType : String)
case class Controller(name : String, routeMetaData : List[String], methods : List[Method])
implicit val paramW = upickle.default.macroW[Parameter]
implicit val methodW = upickle.default.macroW[Method]
implicit val controllerW = upickle.default.macroW[Controller]
def cleanAnnotation(annotationValue:String): String = {
annotationValue.replace("[","").replace("]","").replace("\"","").trim()
}
val attackSurface = cpg.annotation.name(".*(RequestMapping|GetMapping|PostMapping|PutMapping|DeleteMapping|PatchMapping).*").map { a =>
Method(a.start.method.name.l.head,
a.start.parameterAssign.value.code.l.map(cleanAnnotation(_)),
a.start.method.parameter.l.map { p=>
Parameter(p.name, p.start.evalType.l.head)
}.filter(!_.name.equals("this")),
a.start.method.methodReturn.l.map(_.typeFullName).head
)
}.l.distinct
upickle.default.write(attackSurface, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment