Skip to content

Commit e434585

Browse files
committed
Merge branch 'release-0.6'
2 parents 5c16f86 + b98e67b commit e434585

39 files changed

+951
-396
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
First off, thank you for considering contributing to NMapGUI. All together we can make this proyect big and really useful.
1+
First off, thank you for considering contributing to NMapGUI. All together we can make this project big and really useful.
22

3-
In order to report Issues, suggest Enhancements or ask questions, you can use the Issues tab.
3+
In order to report Issues, suggest Enhancements or ask Questions, you can use the Issues tab.
44

55
However, if you have any code contribution, it should be fully tested and functional before it gets reviewed.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Discord](https://img.shields.io/discord/357162772108148736.svg?colorB=7282ea)](https://discord.gg/5s6kUA6)
1010

1111

12-
NMapGUI is an advanced graphical user interface for NMap network analysis tool. It allows to extend and ease the typical usage of NMap by providen a visual and fast interface with the application
12+
NMapGUI is an advanced graphical user interface for NMap network analysis tool. It allows to extend and ease the typical usage of NMap by providing a visual and fast interface with the application
1313

1414
If you have any questions about NMapGUI usage or want to get in contact with me, please visit:
1515

@@ -25,14 +25,15 @@ If you have any questions about NMapGUI usage or want to get in contact with me,
2525
* Interactive traceroute graph output
2626
* Saving output as XML.
2727
* Output minimizing, maximizing and deleting.
28-
* Menu to find most of nmap options.
28+
* Menu to find most of nmap options and your system's scripts.
2929
* Start and stop the webapp at any moment.
3030

3131
### Zenmap vs NMapGUI
3232
| | Zenmap| NMapGUI |
3333
| ---: | :---: | :---: |
3434
| __Multiple parallel commands__ | :no_entry_sign: | :white_check_mark:|
3535
| __Option menu__ | :no_entry_sign: | :white_check_mark: |
36+
| __ᴺᴱᵂ System's script list__ | :no_entry_sign: | :white_check_mark: |
3637
| __Automatic HTML report__ | :no_entry_sign: | :white_check_mark:|
3738
| __Pretty interface__ | :poop: | :white_check_mark:|
3839
| __Graph output__ | :white_check_mark: | :sparkles::white_check_mark::sparkles: |
@@ -61,7 +62,7 @@ On progress: Menu creation
6162

6263
For the moment, you will have to execute the jar file. If you have java properly configured in your system, it should work just by double-clicking the jar file. Otherwise, you will have to launch it with your console. For that I recommend the following command on Linux:
6364

64-
`nohup java -jar nmapGUI-0.5.1-snapshot.jar $`
65+
`nohup java -jar nmapGUI-0.6-snapshot.jar $`
6566

6667
as it will let you close the console and still use the app.
6768

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.uniovi.nmapgui</groupId>
77
<artifactId>nmapGUI</artifactId>
8-
<version>0.5.1-SNAPSHOT</version>
8+
<version>0.6-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>NMapGUI</name>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.uniovi.nmapgui;
2+
3+
import java.io.InputStream;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import javax.xml.bind.JAXBContext;
10+
import javax.xml.bind.JAXBException;
11+
import javax.xml.bind.Unmarshaller;
12+
13+
import com.uniovi.nmapgui.executor.CommandExecutor;
14+
import com.uniovi.nmapgui.executor.CommandExecutorImpl;
15+
import com.uniovi.nmapgui.executor.CommandExecutorObserver;
16+
import com.uniovi.nmapgui.model.Command;
17+
import com.uniovi.nmapgui.model.Script;
18+
import com.uniovi.nmapgui.model.ScriptHelp;
19+
import com.uniovi.nmapgui.model.menu.Menu;
20+
21+
public class InitialConfigurator implements CommandExecutorObserver{
22+
23+
private Map<String,List<Script>> scriptCategories = new HashMap<>();
24+
private Menu menu;
25+
26+
public Map<String, List<Script>> getScriptCategories() {
27+
return scriptCategories;
28+
}
29+
30+
public void setScriptCategories(Map<String, List<Script>> scriptCategories) {
31+
this.scriptCategories = scriptCategories;
32+
}
33+
34+
public Menu getMenu() {
35+
return menu;
36+
}
37+
38+
public void setMenu(Menu menu) {
39+
this.menu = menu;
40+
}
41+
42+
public void configure(){
43+
44+
try {
45+
loadMenu();
46+
} catch (JAXBException e) {
47+
// TODO Auto-generated catch block
48+
e.printStackTrace();
49+
}
50+
Command command = new Command("--script-help all");
51+
CommandExecutor executor = new CommandExecutorImpl(command);
52+
executor.addObserver(this);
53+
executor.execute();
54+
}
55+
56+
private void loadMenu() throws JAXBException {
57+
InputStream xml = InitialConfigurator.class.getClassLoader()
58+
.getResourceAsStream("menu.xml");
59+
JAXBContext jaxbContext = JAXBContext.newInstance(Menu.class);
60+
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
61+
Menu menu = (Menu)unmarshaller.unmarshal(xml);
62+
this.setMenu(menu);
63+
64+
65+
}
66+
67+
@Override
68+
public void finishedCommand(Command cmd) {
69+
computeMap(cmd.getOutput().getScriptHelp());
70+
}
71+
72+
private void computeMap(ScriptHelp scriptHelp){
73+
if (scriptHelp!=null){
74+
for (Script script : scriptHelp.getScripts()){
75+
for (String category : script.getCategories()){
76+
if (!scriptCategories.containsKey(category))
77+
scriptCategories.put(category,new ArrayList<Script>());
78+
scriptCategories.get(category).add(script);
79+
}
80+
}
81+
}
82+
}
83+
}

src/main/java/com/uniovi/nmapgui/NMapGuiApplication.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
77
import org.springframework.scheduling.annotation.EnableAsync;
88

9+
910
@SpringBootApplication
1011
@EnableAsync
1112
public class NMapGuiApplication extends AsyncConfigurerSupport {
12-
13+
1314
public static ConfigurableApplicationContext mainExec(String[] args) {
15+
1416
return SpringApplication.run(NMapGuiApplication.class, args);
1517
}
1618

src/main/java/com/uniovi/nmapgui/WebController.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10+
import javax.annotation.PostConstruct;
11+
1012
import org.springframework.core.io.InputStreamResource;
1113
import org.springframework.http.MediaType;
1214
import org.springframework.http.ResponseEntity;
@@ -29,13 +31,21 @@ public class WebController implements CommandExecutorObserver{
2931
private List<Command> finishedCommands = new ArrayList<Command>();
3032
private Command command;
3133
private boolean finishedCommandQueued=false;
34+
private InitialConfigurator config = new InitialConfigurator();
35+
3236

37+
@PostConstruct
38+
public void init(){
39+
config.configure();
40+
}
3341

3442
@GetMapping("/nmap")
3543
public String command(Model model) {
3644

3745
command = new Command();
3846
model.addAttribute("command", command);
47+
model.addAttribute("scriptCategories", config.getScriptCategories());
48+
model.addAttribute("menu", config.getMenu());
3949
model.addAttribute("commands", ongoingCommands);
4050
model.addAttribute("commands", finishedCommands);
4151
finishedCommandQueued=true;
@@ -46,13 +56,10 @@ public String command(Model model) {
4656
public String command(Model model, @RequestParam String code) {
4757
command = new Command(code);
4858
ongoingCommands.add(0,command);
49-
CommandExecutor executor = new CommandExecutorImpl(command);
50-
executor.addObserver(this);
51-
executor.execute();
59+
executeCommand(command);
5260
model.addAttribute("command", command);
5361
model.addAttribute("commands", ongoingCommands);
54-
55-
62+
5663
return "fragments/contents :: ongoing";
5764
}
5865

@@ -117,5 +124,11 @@ public void finishedCommand(Command cmd){
117124
finishedCommands.add(0,cmd);
118125
finishedCommandQueued = true;
119126
}
127+
128+
public void executeCommand(Command command){
129+
CommandExecutor executor = new CommandExecutorImpl(command);
130+
executor.addObserver(this);
131+
executor.execute();
132+
}
120133

121134
}

src/main/java/com/uniovi/nmapgui/executor/CommandExecutorImpl.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package com.uniovi.nmapgui.executor;
22

3-
import java.io.*;
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.InputStreamReader;
8+
import java.io.StringReader;
49
import java.text.SimpleDateFormat;
510
import java.util.ArrayList;
611
import java.util.Arrays;
712
import java.util.Date;
813
import java.util.List;
914
import java.util.regex.Matcher;
1015
import java.util.regex.Pattern;
16+
1117
import javax.xml.bind.JAXBContext;
1218
import javax.xml.bind.Unmarshaller;
1319

14-
import com.uniovi.nmapgui.model.*;
20+
import com.uniovi.nmapgui.model.Command;
21+
import com.uniovi.nmapgui.model.ExecutionObjectFactory;
22+
import com.uniovi.nmapgui.model.Scan;
23+
import com.uniovi.nmapgui.model.ScriptHelp;
1524
import com.uniovi.nmapgui.util.TransInfoHtml;
1625

1726
public class CommandExecutorImpl implements CommandExecutor{
@@ -160,12 +169,16 @@ public void readXML() {
160169
while ((sCurrentLine = br.readLine()) != null) {
161170
sb.append(sCurrentLine);
162171
}
163-
JAXBContext jaxbContext = JAXBContext.newInstance(Scan.class);
172+
173+
JAXBContext jaxbContext = JAXBContext.newInstance(ExecutionObjectFactory.class);
164174
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
165175
StringReader reader = new StringReader(sb.toString());
166-
Scan scan = (Scan) unmarshaller.unmarshal(reader);
176+
Object execution = unmarshaller.unmarshal(reader);
167177
cmd.getOutput().setXml(TransInfoHtml.transformToHtml(sb.toString()));
168-
cmd.getOutput().setScan(scan);
178+
if (execution instanceof Scan)
179+
cmd.getOutput().setScan((Scan) execution);
180+
else if (execution instanceof ScriptHelp)
181+
cmd.getOutput().setScriptHelp((ScriptHelp) execution);
169182

170183
} catch (Exception e) {
171184
e.printStackTrace();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.uniovi.nmapgui.model;
2+
3+
import javax.xml.bind.annotation.XmlRegistry;
4+
5+
@XmlRegistry
6+
public class ExecutionObjectFactory {
7+
8+
public Scan createScan() {
9+
return new Scan();
10+
}
11+
12+
public ScriptHelp createScriptHelp() {
13+
return new ScriptHelp();
14+
}
15+
}

src/main/java/com/uniovi/nmapgui/model/Output.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class Output {
77
private String xml="";
88
private String filename;
99
private Scan scan = new Scan();
10+
private ScriptHelp scriptHelp = new ScriptHelp();
11+
1012
private String id = "el3-"+Math.abs(new Random().nextInt());
1113

1214
public String getText() {
@@ -50,4 +52,12 @@ public void setScan(Scan scan) {
5052
this.scan = scan;
5153
}
5254

55+
public ScriptHelp getScriptHelp() {
56+
return scriptHelp;
57+
}
58+
59+
public void setScriptHelp(ScriptHelp scriptHelp) {
60+
this.scriptHelp = scriptHelp;
61+
}
62+
5363
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.uniovi.nmapgui.model;
2+
3+
import java.util.List;
4+
5+
import javax.xml.bind.annotation.XmlAttribute;
6+
import javax.xml.bind.annotation.XmlElement;
7+
import javax.xml.bind.annotation.XmlElementWrapper;
8+
9+
public class Script {
10+
private List<String> categories;
11+
private String description;
12+
private String filename;
13+
private String name;
14+
15+
public String getName() {
16+
if (name!=null)
17+
return name;
18+
String[] split = filename.split("/");
19+
return name=split[split.length-1].replace(".nse", "");
20+
}
21+
22+
public void setName(String name) {
23+
this.name = name;
24+
}
25+
26+
@XmlElementWrapper(name="categories", required=false)
27+
@XmlElement(name="category", required=false)
28+
public List<String> getCategories() {
29+
return categories;
30+
}
31+
32+
public void setCategories(List<String> categories) {
33+
this.categories = categories;
34+
}
35+
36+
@XmlElement(name="description")
37+
public String getDescription() {
38+
return description;
39+
}
40+
41+
public void setDescription(String description) {
42+
this.description = description;
43+
}
44+
45+
@XmlAttribute(name="filename")
46+
public String getFilename() {
47+
return filename;
48+
}
49+
50+
public void setFilename(String filename) {
51+
this.filename = filename;
52+
}
53+
54+
55+
56+
}

0 commit comments

Comments
 (0)