15
15
@click .command ()
16
16
@click .argument ('ip' )
17
17
@click .option ('-p' , 'port' , default = 161 , help = 'Port to use' )
18
+ @click .option ('-c' , 'community' , default = None , help = 'Community (default: list of most used)' )
18
19
@click .option ('-s' , 'stop' , is_flag = True , default = False , help = 'Stop after first match' )
19
20
@click .option ('-v' , 'verbose' , is_flag = True , default = False , help = 'Verbose' )
20
- def cmd_crack_snmp (ip , port , stop , verbose ):
21
+ def cmd_crack_snmp (ip , community , port , stop , verbose ):
21
22
"""Launches snmp-get queries against an IP, and tells you when
22
23
finds a valid community string (is a simple SNMP cracker).
23
24
@@ -40,26 +41,32 @@ def cmd_crack_snmp(ip, port, stop, verbose):
40
41
DATADIR = os .path .abspath (os .path .join (FILEDIR , '../data' ))
41
42
COMMFILE = Path (os .path .abspath (os .path .join (DATADIR , 'dict_snmp.txt' )))
42
43
43
- with COMMFILE .open () as cf :
44
- communities = cf .read ().split ('\n ' )
44
+ if community :
45
+ communities = [community ]
46
+ else :
47
+ with COMMFILE .open () as cf :
48
+ communities = cf .read ().split ('\n ' )
45
49
46
50
conf .verb = False
47
51
48
- pkt = IP (dst = ip )/ UDP (sport = port , dport = port )/ SNMP (community = "public" , PDU = SNMPget (varbindlist = [SNMPvarbind (oid = ASN1_OID ("1.3.6.1" ))]))
49
-
50
- for community in communities :
52
+ for pkt in IP (dst = ip )/ UDP (sport = port , dport = port )/ SNMP (community = "public" , PDU = SNMPget (varbindlist = [SNMPvarbind (oid = ASN1_OID ("1.3.6.1" ))])):
51
53
52
54
if verbose :
53
- print ('.' , end = '' )
54
- sys .stdout .flush ()
55
+ print (pkt [IP ].dst )
56
+
57
+ for community in communities :
58
+
59
+ if verbose :
60
+ print ('.' , end = '' )
61
+ sys .stdout .flush ()
55
62
56
- pkt [SNMP ].community = community
57
- ans = sr1 (pkt , timeout = 0.5 , verbose = 0 )
63
+ pkt [SNMP ].community = community
64
+ ans = sr1 (pkt , timeout = 0.5 , verbose = 0 )
58
65
59
- if ans and UDP in ans :
60
- print ('\n Community found:' , community )
61
- if stop :
62
- break
66
+ if ans and UDP in ans :
67
+ print ('\n {} - Community found: {}' . format ( pkt [ IP ]. dst , community ) )
68
+ if stop :
69
+ break
63
70
64
71
return True
65
72
0 commit comments