Skip to content

Commit 813bd1f

Browse files
committed
Add -help argument, reorganize source code structure to facilitate the embedded resource
1 parent 326acf0 commit 813bd1f

7 files changed

Lines changed: 65 additions & 11 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<packaging>jar</packaging>
1717

1818
<build>
19-
<sourceDirectory>src</sourceDirectory>
20-
<pluginManagement>
19+
<sourceDirectory>src/main/java</sourceDirectory>
20+
<pluginManagement>
2121
<plugins>
2222
<plugin>
2323
<groupId>org.apache.maven.plugins</groupId>

src/com/denimgroup/threadfix/cli/endpoints/Credentials.java renamed to src/main/java/com/denimgroup/threadfix/cli/endpoints/Credentials.java

File renamed without changes.

src/com/denimgroup/threadfix/cli/endpoints/EndpointJob.java renamed to src/main/java/com/denimgroup/threadfix/cli/endpoints/EndpointJob.java

File renamed without changes.

src/com/denimgroup/threadfix/cli/endpoints/EndpointMain.java renamed to src/main/java/com/denimgroup/threadfix/cli/endpoints/EndpointMain.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@
4040
import com.denimgroup.threadfix.framework.util.EndpointUtil;
4141
import org.apache.commons.io.FileUtils;
4242
import org.apache.commons.io.FilenameUtils;
43+
import org.apache.commons.io.IOUtils;
4344
import org.apache.commons.lang3.StringUtils;
4445
import org.apache.log4j.ConsoleAppender;
4546
import org.apache.log4j.Level;
4647
import org.apache.log4j.Logger;
4748
import org.apache.log4j.PatternLayout;
4849
import org.codehaus.jackson.map.ObjectMapper;
4950

50-
import java.io.File;
51-
import java.io.FileNotFoundException;
52-
import java.io.IOException;
51+
import java.io.*;
5352
import java.net.UnknownHostException;
5453
import java.util.Collection;
5554
import java.util.List;
@@ -359,7 +358,7 @@ private static boolean checkArguments(String[] args) {
359358
}
360359
} else if (arg.equalsIgnoreCase("-help")) {
361360
printHelp();
362-
return false;
361+
System.exit(0);
363362
} else {
364363
println("Received unsupported option " + arg + ", run with -help to see available flags.");
365364
return false;
@@ -380,11 +379,13 @@ static void printError() {
380379
}
381380

382381
static void printHelp() {
383-
StringBuilder helpMessage = new StringBuilder();
384-
385-
helpMessage.append("Attack Surface Detector CLI Tool");
386-
387-
println(helpMessage.toString());
382+
InputStream helpFileStream = EndpointMain.class.getResourceAsStream("/help.txt");
383+
try {
384+
String helpInfo = IOUtils.toString(helpFileStream);
385+
println(helpInfo);
386+
} catch (IOException e) {
387+
e.printStackTrace();
388+
}
388389
}
389390

390391
private static int printEndpointWithVariants(int i, int currentDepth, Endpoint endpoint) {

src/com/denimgroup/threadfix/cli/endpoints/EndpointTester.java renamed to src/main/java/com/denimgroup/threadfix/cli/endpoints/EndpointTester.java

File renamed without changes.

src/com/denimgroup/threadfix/cli/endpoints/EndpointValidation.java renamed to src/main/java/com/denimgroup/threadfix/cli/endpoints/EndpointValidation.java

File renamed without changes.

src/main/resources/help.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Attack Surface Detector CLI
2+
https://github.com/secdec/attack-surface-detector-cli
3+
4+
A tool to detect endpoints from source code. Can output these endpoints in multiple JSON formats,
5+
or output to the console (by default) to inspect the quality and coverage of the detected endpoints.
6+
7+
Usage:
8+
java -jar attack-surface-detector-cli.jar <source-code-path> [flags]
9+
10+
Flags:
11+
-debug -- Print debug information during endpoint detection
12+
13+
-simple -- Print only endpoint detection summary, without the full list
14+
of detected endpoints
15+
16+
-path-list-file=<PATH> -- Detect endpoints from all source code paths listed in the given file
17+
18+
-defaultFramework=<FRAMEWORK> -- Parse the source code using the given framework type
19+
Available values:
20+
DETECT : Attempt to automatically detect the framework
21+
JSP : Java JSP/Servlets
22+
SPRING_MVC : Java Spring MVC
23+
STRUTS : Java Struts
24+
DOT_NET_MVC : ASP.NET MVC/WebAPI
25+
DOT_NET_WEB_FORMS : ASP.NET Web Forms
26+
PYTHON : Django
27+
Rails : Ruby on Rails
28+
29+
-help -- Displays this message
30+
31+
[JSON Output]
32+
-json -- Print only simple-format JSON to the console
33+
Simple-format JSON uses a common format for all generated endpoints
34+
regardless of framework.
35+
36+
-full-json -- Print full JSON information to the console
37+
Full-format JSON uses unique data formats depending on the framework
38+
that declared the endpoints. Should be used with the
39+
astam-correlator.threadfix-ham module available on Maven.
40+
41+
-output-file=<PATH> -- Writes generated JSON to the specified file path.
42+
Must be used with the -json or -full-json flags; otherwise, has no effect.
43+
44+
45+
46+
[Quality Testing]
47+
-validation-server=<BASE_URL> -- Run HTTP requests against the detected endpoints relative to the
48+
given BASE_URL; ie http://localhost:8080/mywebapp
49+
50+
-validation-server-auth=<CREDS> -- Use the given HTTP headers when validating endpoints against
51+
a test server. Takes the format: "HEADER=VALUE;HEADER=VALUE;..."
52+
Must be used with the -validation-server flag; otherwise, has
53+
no effect.

0 commit comments

Comments
 (0)