forked from cSploit/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNMap.java
More file actions
202 lines (164 loc) · 6.04 KB
/
Copy pathNMap.java
File metadata and controls
202 lines (164 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* This file is part of the cSploit.
*
* Copyleft of Massimo Dragano aka tux_mind <tux_mind@csploit.org>
*
* cSploit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* cSploit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with cSploit. If not, see <http://www.gnu.org/licenses/>.
*/
package org.csploit.android.tools;
import android.text.TextUtils;
import org.csploit.android.core.Child;
import org.csploit.android.core.ChildManager;
import org.csploit.android.core.Logger;
import org.csploit.android.events.Event;
import org.csploit.android.events.Hop;
import org.csploit.android.events.Os;
import org.csploit.android.events.Port;
import org.csploit.android.net.Network;
import org.csploit.android.net.Target;
import java.util.LinkedList;
public class NMap extends Tool {
public static abstract class TraceReceiver extends Child.EventReceiver
{
public void onEnd( int exitCode ) {
if( exitCode != 0 )
Logger.error("nmap exited with code " + exitCode );
}
public void onDeath( int signal ) {
Logger.error("nmap killed by signal " + signal);
}
public void onEvent(Event e) {
if(e instanceof Hop) {
Hop hop = (Hop)e;
onHop(hop.hop, hop.usec, hop.node.getHostAddress(), hop.name);
} else {
Logger.error("unknown event: " + e);
}
}
public abstract void onHop( int hop, long usec, String address, String name );
}
public static abstract class SynScanReceiver extends Child.EventReceiver
{
public void onEnd( int exitCode ) {
if( exitCode != 0 )
Logger.error( "nmap exited with code " + exitCode );
}
public void onDeath(int signal) {
Logger.error("nmap killed by signal " + signal);
}
public void onEvent( Event e) {
if(e instanceof Port) {
Port p = (Port)e;
onPortFound(p.port, p.protocol);
} else {
Logger.error("unkown event: " + e);
}
}
public abstract void onPortFound( int port, String protocol );
}
public static abstract class InspectionReceiver extends Child.EventReceiver
{
public void onEnd( int exitCode ) {
if( exitCode != 0 )
Logger.error( "nmap exited with code " + exitCode );
}
public void onDeath(int signal) {
Logger.error( "nmap killed by signal " + signal);
}
public void onEvent(Event e) {
if(e instanceof Port) {
Port p = (Port)e;
if(p.service == null) {
onOpenPortFound(p.port, p.protocol);
} else {
onServiceFound(p.port, p.protocol, p.service, p.version);
}
} else if(e instanceof Os) {
Os os = (Os) e;
onOsFound(os.os);
onDeviceFound(os.type);
} else {
Logger.error("unknown event: " + e);
}
}
public abstract void onOpenPortFound( int port, String protocol );
public abstract void onServiceFound( int port, String protocol, String service, String version );
public abstract void onOsFound( String os );
public abstract void onDeviceFound( String device );
}
public NMap() {
mHandler = "nmap";
mCmdPrefix = null;
}
public Child trace( Target target, boolean resolve, TraceReceiver receiver ) throws ChildManager.ChildNotStartedException {
String cmd = String.format("-sn --traceroute --privileged --send-ip --system-dns -%c %s",
(resolve ? 'R' : 'n'), target.getCommandLineRepresentation());
return super.async(cmd, receiver );
}
public Child synScan( Target target, SynScanReceiver receiver, String custom ) throws ChildManager.ChildNotStartedException {
String command = "-sS -P0 --privileged --send-ip --system-dns -vvv ";
if( custom != null )
command += "-p " + custom + " ";
command += target.getCommandLineRepresentation();
Logger.debug( "synScan - " + command );
return super.async( command, receiver );
}
public Child synScan( Target target, SynScanReceiver receiver) throws ChildManager.ChildNotStartedException {
return synScan(target, receiver, null);
}
public Child customScan( Target target, SynScanReceiver receiver, String custom ) throws ChildManager.ChildNotStartedException {
String command = "-vvv ";
if( custom != null )
command += custom + " ";
command += target.getCommandLineRepresentation();
Logger.debug( "customScan - " + command );
return super.async( command, receiver );
}
public Child inpsect( Target target, InspectionReceiver receiver, boolean focusedScan ) throws ChildManager.ChildNotStartedException {
String cmd;
LinkedList<Integer> tcp,udp;
Network.Protocol protocol;
int pNumber;
if(focusedScan)
{
tcp = new LinkedList<Integer>();
udp = new LinkedList<Integer>();
for( Target.Port p : target.getOpenPorts()) {
protocol = p.getProtocol();
pNumber = p.getNumber();
if(protocol.equals(Network.Protocol.TCP)) {
if(!tcp.contains(pNumber))
tcp.add(pNumber);
} else if(protocol.equals(Network.Protocol.UDP)) {
if(!udp.contains(pNumber))
udp.add(pNumber);
}
}
cmd = "-T4 -sV -O --privileged --send-ip --system-dns -Pn -oX - ";
if(tcp.size() + udp.size() > 0) {
cmd+= "-p ";
if(tcp.size()>0)
cmd+= "T:" + TextUtils.join(",",tcp);
if(udp.size()>0)
cmd+= "U:" + TextUtils.join(",", udp);
cmd+= " ";
}
cmd+= target.getCommandLineRepresentation();
}
else
cmd = "-T4 -F -O -sV --privileged --send-ip --system-dns -oX - " + target.getCommandLineRepresentation();
Logger.debug( "Inspect - " + cmd );
return super.async( cmd, receiver);
}
}