Skip to content

Commit

Permalink
Merge branch 'release-0.4' - Added graph view to master
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-cues committed Sep 11, 2017
2 parents fb23f5d + 87ce60c commit 421bd6c
Show file tree
Hide file tree
Showing 23 changed files with 1,410 additions and 38 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ addons:
apt:
packages:
- nmap


before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3

before_install:
- pip install --user codecov

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ If you have any questions about NMapGUI usage or want to get in contact with me,
* Multiple command execution at the same time.
* Standard NMap output.
* HTML report NMap output.
* Interactive traceroute graph output
* Saving output as XML.
* Output minimizing, maximizing and deleting.
* Menu to find most of nmap options.
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.3.1-SNAPSHOT</version>
<version>0.4-SNAPSHOT</version>
<packaging>jar</packaging>

<name>NMapGUI</name>
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/uniovi/nmapgui/NMapLoaderWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class NMapLoaderWindow extends JFrame {
private static final String IMG_PATH = "static/img/header.jpg";


private JLabel image;
private JButton start;
private JButton stop;
private ConfigurableApplicationContext springContext;
Expand Down Expand Up @@ -77,15 +76,15 @@ private JPanel image() {
} catch (IOException e) {
e.printStackTrace();
}
ImageIcon icon = new ImageIcon(img);
image = new JLabel(icon);
image.setLayout(new FlowLayout(FlowLayout.RIGHT));

ImageIcon icon = new ImageIcon(img);
JLabel image = new JLabel(icon);
image.setLayout(new FlowLayout(FlowLayout.RIGHT));
image.setName("image");

go= new JButton("Go!");
go.setEnabled(false);
go.addActionListener(new ActionListener() {
go= new JButton("Go!");
go.setEnabled(false);
go.setName("go");
go.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Expand All @@ -109,6 +108,7 @@ private JPanel buttons() {
gl.setVgap(5);
buttons.setLayout(gl);
start = new JButton("Start NMapGUI");
start.setName("start");
if(!nmapInstalled){
start.setEnabled(false);
start.setText("NMap is not installed");
Expand All @@ -129,6 +129,7 @@ public void actionPerformed(ActionEvent e) {
buttons.add(start);

stop = new JButton("Nmap not running");
stop.setName("stop");
stop.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Expand Down
68 changes: 53 additions & 15 deletions src/main/java/com/uniovi/nmapgui/executor/CommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
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.util.TransInfoHtml;
Expand All @@ -18,23 +21,17 @@ public class CommandExecutor {


public CommandExecutor(Command command) {
this();
cmd=command;
}
public CommandExecutor(){};


public boolean execute(){
String filename= "nmap-scan_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
.format(new Date())+ ".xml";

this.cmd.getOutput().setFilename(filename);
tempPath=tempPath + filename;
List<String> commandsList = new ArrayList<String>();
commandsList.add("nmap");
commandsList.addAll(Arrays.asList(cmd.getText().split(" ")));
commandsList.addAll(Arrays.asList(new String[]{"-oX" , getTempPath(), "--webxml"}));
String[] command = composeCommand();

try {
Process p = Runtime.getRuntime().exec(commandsList.toArray(new String[]{}));
Process p = Runtime.getRuntime().exec(command);
final InputStream stream = p.getInputStream();
final InputStream errors = p.getErrorStream();
commandThread = new Thread(new Runnable() {
Expand All @@ -43,9 +40,9 @@ public void run() {
BufferedReader errorReader = null;

try {
boolean firstLine=true;
reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
cmd.getOutput().setText("<pre></pre>");
while ((line = reader.readLine()) != null) {
line=escape(line);
if (line.contains( " open "))
Expand All @@ -54,13 +51,23 @@ else if (line.contains( " closed "))
line="<span class=\"closed\">"+line+"</span>";
else if (line.contains( " filtered "))
line="<span class=\"filtered\">"+line+"</span>";
cmd.getOutput().setText(cmd.getOutput().getText().replaceAll("</pre>", "\n")+line+"</pre>");
String jump = "\n";
if(firstLine)
jump="";
cmd.getOutput().setText(cmd.getOutput().getText()+jump+line);
firstLine=false;

}
errorReader = new BufferedReader(new InputStreamReader(errors));
while ((line = errorReader.readLine()) != null) {
line=escape(line);
line="<span class=\"closed\">"+line+"</span>";
cmd.getOutput().setText(cmd.getOutput().getText().replaceAll("</pre>", "\n")+"<i>"+line+"</i></pre>");
String jump = "\n";
if(firstLine)
jump="";
cmd.getOutput().setText(cmd.getOutput().getText()+jump+"<i>"+line+"</i>");
firstLine=false;

}

} catch (Exception e) {
Expand All @@ -84,6 +91,32 @@ else if (line.contains( " filtered "))
}
return true;
}

private String[] composeCommand() {

String filename= "nmap-scan_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
.format(new Date())+ ".xml";

this.cmd.getOutput().setFilename(filename);
tempPath=tempPath + filename;
List<String> commandList = new ArrayList<String>();
commandList.add("nmap");
commandList.addAll(splitOptions());
commandList.addAll(Arrays.asList(new String[]{"-oX" , getTempPath(), "--webxml"}));

return commandList.toArray(new String[]{});

}

private List<String> splitOptions(){
List<String> options = new ArrayList<>();
//Splits string by spaces other than the ones in substring quotes
Matcher matcher = Pattern.compile("\\s*([^(\"|\')]\\S*|\".+?\"|\'.+?\')\\s*").matcher(cmd.getText());
while (matcher.find())
options.add(matcher.group(1));

return options;
}

private String escape(String str) {
String line=str;
Expand Down Expand Up @@ -123,8 +156,13 @@ public void readXML() {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
sb.append(sCurrentLine);
}
}
JAXBContext jaxbContext = JAXBContext.newInstance(Scan.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(sb.toString());
Scan scan = (Scan) unmarshaller.unmarshal(reader);
cmd.getOutput().setXml(TransInfoHtml.transformToHtml(sb.toString()));
cmd.getOutput().setScan(scan);

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

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

@XmlRootElement(name="address")
public class Address {

private String address;

public Address(String address) {
setAddress(address);
}
public Address(){}

@XmlAttribute(name="addr")
public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

@Override
public String toString() {
return "Address [address=" + getAddress() + "]";
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Address other = (Address) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
return true;
}



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

import java.util.HashSet;
import java.util.Set;

import javax.xml.bind.annotation.XmlAttribute;

public class Hop {

private String address;
private String host;

@XmlAttribute(name="ipaddr")
public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

@XmlAttribute(name="host")
public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

@Override
public String toString() {
return "Hop [address=" + getAddress() + ", host=" + getHost() + "]";
}

public Host toHost(){
Host host = new Host();
host.setAddress(new Address(address));
Set<Hostname> set = new HashSet<Hostname>();
if (host!=null)
set.add(new Hostname(this.host));
host.setHostNames(set);

return host;
}


}
Loading

0 comments on commit 421bd6c

Please sign in to comment.