Skip to content

Commit

Permalink
Merge branch 'release-0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-cues committed Oct 24, 2017
2 parents 5c16f86 + b98e67b commit e434585
Show file tree
Hide file tree
Showing 39 changed files with 951 additions and 396 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
First off, thank you for considering contributing to NMapGUI. All together we can make this proyect big and really useful.
First off, thank you for considering contributing to NMapGUI. All together we can make this project big and really useful.

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

However, if you have any code contribution, it should be fully tested and functional before it gets reviewed.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Discord](https://img.shields.io/discord/357162772108148736.svg?colorB=7282ea)](https://discord.gg/5s6kUA6)


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
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

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

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

### Zenmap vs NMapGUI
| | Zenmap| NMapGUI |
| ---: | :---: | :---: |
| __Multiple parallel commands__ | :no_entry_sign: | :white_check_mark:|
| __Option menu__ | :no_entry_sign: | :white_check_mark: |
| __ᴺᴱᵂ System's script list__ | :no_entry_sign: | :white_check_mark: |
| __Automatic HTML report__ | :no_entry_sign: | :white_check_mark:|
| __Pretty interface__ | :poop: | :white_check_mark:|
| __Graph output__ | :white_check_mark: | :sparkles::white_check_mark::sparkles: |
Expand Down Expand Up @@ -61,7 +62,7 @@ On progress: Menu creation

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:

`nohup java -jar nmapGUI-0.5.1-snapshot.jar $`
`nohup java -jar nmapGUI-0.6-snapshot.jar $`

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

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.uniovi.nmapgui</groupId>
<artifactId>nmapGUI</artifactId>
<version>0.5.1-SNAPSHOT</version>
<version>0.6-SNAPSHOT</version>
<packaging>jar</packaging>

<name>NMapGUI</name>
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/uniovi/nmapgui/InitialConfigurator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.uniovi.nmapgui;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import com.uniovi.nmapgui.executor.CommandExecutor;
import com.uniovi.nmapgui.executor.CommandExecutorImpl;
import com.uniovi.nmapgui.executor.CommandExecutorObserver;
import com.uniovi.nmapgui.model.Command;
import com.uniovi.nmapgui.model.Script;
import com.uniovi.nmapgui.model.ScriptHelp;
import com.uniovi.nmapgui.model.menu.Menu;

public class InitialConfigurator implements CommandExecutorObserver{

private Map<String,List<Script>> scriptCategories = new HashMap<>();
private Menu menu;

public Map<String, List<Script>> getScriptCategories() {
return scriptCategories;
}

public void setScriptCategories(Map<String, List<Script>> scriptCategories) {
this.scriptCategories = scriptCategories;
}

public Menu getMenu() {
return menu;
}

public void setMenu(Menu menu) {
this.menu = menu;
}

public void configure(){

try {
loadMenu();
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Command command = new Command("--script-help all");
CommandExecutor executor = new CommandExecutorImpl(command);
executor.addObserver(this);
executor.execute();
}

private void loadMenu() throws JAXBException {
InputStream xml = InitialConfigurator.class.getClassLoader()
.getResourceAsStream("menu.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Menu.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Menu menu = (Menu)unmarshaller.unmarshal(xml);
this.setMenu(menu);


}

@Override
public void finishedCommand(Command cmd) {
computeMap(cmd.getOutput().getScriptHelp());
}

private void computeMap(ScriptHelp scriptHelp){
if (scriptHelp!=null){
for (Script script : scriptHelp.getScripts()){
for (String category : script.getCategories()){
if (!scriptCategories.containsKey(category))
scriptCategories.put(category,new ArrayList<Script>());
scriptCategories.get(category).add(script);
}
}
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/uniovi/nmapgui/NMapGuiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;


@SpringBootApplication
@EnableAsync
public class NMapGuiApplication extends AsyncConfigurerSupport {

public static ConfigurableApplicationContext mainExec(String[] args) {

return SpringApplication.run(NMapGuiApplication.class, args);
}

Expand Down
23 changes: 18 additions & 5 deletions src/main/java/com/uniovi/nmapgui/WebController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -29,13 +31,21 @@ public class WebController implements CommandExecutorObserver{
private List<Command> finishedCommands = new ArrayList<Command>();
private Command command;
private boolean finishedCommandQueued=false;
private InitialConfigurator config = new InitialConfigurator();


@PostConstruct
public void init(){
config.configure();
}

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

command = new Command();
model.addAttribute("command", command);
model.addAttribute("scriptCategories", config.getScriptCategories());
model.addAttribute("menu", config.getMenu());
model.addAttribute("commands", ongoingCommands);
model.addAttribute("commands", finishedCommands);
finishedCommandQueued=true;
Expand All @@ -46,13 +56,10 @@ public String command(Model model) {
public String command(Model model, @RequestParam String code) {
command = new Command(code);
ongoingCommands.add(0,command);
CommandExecutor executor = new CommandExecutorImpl(command);
executor.addObserver(this);
executor.execute();
executeCommand(command);
model.addAttribute("command", command);
model.addAttribute("commands", ongoingCommands);



return "fragments/contents :: ongoing";
}

Expand Down Expand Up @@ -117,5 +124,11 @@ public void finishedCommand(Command cmd){
finishedCommands.add(0,cmd);
finishedCommandQueued = true;
}

public void executeCommand(Command command){
CommandExecutor executor = new CommandExecutorImpl(command);
executor.addObserver(this);
executor.execute();
}

}
23 changes: 18 additions & 5 deletions src/main/java/com/uniovi/nmapgui/executor/CommandExecutorImpl.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package com.uniovi.nmapgui.executor;

import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import com.uniovi.nmapgui.model.*;
import com.uniovi.nmapgui.model.Command;
import com.uniovi.nmapgui.model.ExecutionObjectFactory;
import com.uniovi.nmapgui.model.Scan;
import com.uniovi.nmapgui.model.ScriptHelp;
import com.uniovi.nmapgui.util.TransInfoHtml;

public class CommandExecutorImpl implements CommandExecutor{
Expand Down Expand Up @@ -160,12 +169,16 @@ public void readXML() {
while ((sCurrentLine = br.readLine()) != null) {
sb.append(sCurrentLine);
}
JAXBContext jaxbContext = JAXBContext.newInstance(Scan.class);

JAXBContext jaxbContext = JAXBContext.newInstance(ExecutionObjectFactory.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(sb.toString());
Scan scan = (Scan) unmarshaller.unmarshal(reader);
Object execution = unmarshaller.unmarshal(reader);
cmd.getOutput().setXml(TransInfoHtml.transformToHtml(sb.toString()));
cmd.getOutput().setScan(scan);
if (execution instanceof Scan)
cmd.getOutput().setScan((Scan) execution);
else if (execution instanceof ScriptHelp)
cmd.getOutput().setScriptHelp((ScriptHelp) execution);

} catch (Exception e) {
e.printStackTrace();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/uniovi/nmapgui/model/ExecutionObjectFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.uniovi.nmapgui.model;

import javax.xml.bind.annotation.XmlRegistry;

@XmlRegistry
public class ExecutionObjectFactory {

public Scan createScan() {
return new Scan();
}

public ScriptHelp createScriptHelp() {
return new ScriptHelp();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/uniovi/nmapgui/model/Output.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class Output {
private String xml="";
private String filename;
private Scan scan = new Scan();
private ScriptHelp scriptHelp = new ScriptHelp();

private String id = "el3-"+Math.abs(new Random().nextInt());

public String getText() {
Expand Down Expand Up @@ -50,4 +52,12 @@ public void setScan(Scan scan) {
this.scan = scan;
}

public ScriptHelp getScriptHelp() {
return scriptHelp;
}

public void setScriptHelp(ScriptHelp scriptHelp) {
this.scriptHelp = scriptHelp;
}

}
56 changes: 56 additions & 0 deletions src/main/java/com/uniovi/nmapgui/model/Script.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.uniovi.nmapgui.model;

import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

public class Script {
private List<String> categories;
private String description;
private String filename;
private String name;

public String getName() {
if (name!=null)
return name;
String[] split = filename.split("/");
return name=split[split.length-1].replace(".nse", "");
}

public void setName(String name) {
this.name = name;
}

@XmlElementWrapper(name="categories", required=false)
@XmlElement(name="category", required=false)
public List<String> getCategories() {
return categories;
}

public void setCategories(List<String> categories) {
this.categories = categories;
}

@XmlElement(name="description")
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@XmlAttribute(name="filename")
public String getFilename() {
return filename;
}

public void setFilename(String filename) {
this.filename = filename;
}



}
26 changes: 26 additions & 0 deletions src/main/java/com/uniovi/nmapgui/model/ScriptHelp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.uniovi.nmapgui.model;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "nse-scripts")
public class ScriptHelp {

private List<Script> scripts;

@XmlElement(name="script")
public List<Script> getScripts() {
return scripts;
}

public void setScripts(List<Script> scripts) {
this.scripts = scripts;
}

@Override
public String toString() {
return "Scripts [" + getScripts() + "]";
}
}
Loading

0 comments on commit e434585

Please sign in to comment.