Skip to content

Commit fb677fa

Browse files
committed
new commands habu.nmap.ports habu.nmap.open
1 parent c38b259 commit fb677fa

File tree

5 files changed

+366
-9
lines changed

5 files changed

+366
-9
lines changed

README.md

+125-7
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,43 @@ Options:
620620
```
621621

622622

623+
## habu.firewalk
624+
625+
626+
``` {.sourceCode .bash}
627+
Usage: habu.firewalk [OPTIONS] IP
628+
629+
TCP Port Scanner.
630+
631+
Print the ports that generated a response with the SYN flag or (if show
632+
use -a) all the ports that generated a response.
633+
634+
It's really basic compared with nmap, but who is comparing?
635+
636+
Example:
637+
638+
# habu.tcpscan -p 22,23,80,443 -s 1 45.77.113.133
639+
22 S -> SA
640+
80 S -> SA
641+
443 S -> SA
642+
643+
Options:
644+
-p TEXT Ports to use (default: 80) example: 20-23,80,135
645+
-i TEXT Interface to use
646+
-f TEXT Flags to use (default: S)
647+
-s TEXT Time between probes (default: send all together)
648+
-t INTEGER Timeout for each probe (default: 2 seconds)
649+
-a Show all responses (default: Only containing SYN flag)
650+
-v Verbose output
651+
--help Show this message and exit.
652+
```
653+
654+
623655
## habu.forkbomb
624656

625657

626658
``` {.sourceCode .bash}
627-
Usage: habu.forkbomb [OPTIONS] BOMB
659+
Usage: habu.forkbomb [OPTIONS] [bash|batch|c|haskell|perl|php|python|ruby]
628660
629661
A shortcut to remember how to use fork bombs in different languages.
630662
@@ -660,17 +692,17 @@ Usage: habu.hasher [OPTIONS] [F]
660692
Example:
661693
662694
$ habu.hasher README.rst
663-
md5 : e5828c564f71fea3a12dde8bd5d27063
664-
ripemd160 : ef6886c3b68cb34a44f9ca9336f3cd0732600a84
665-
sha1 : 7bae8076a5771865123be7112468b79e9d78a640
666-
sha512 : 65cfb1cf719b851b4aea5a7f5388068687b1fdfd290817a...
667-
whirlpool : eaccf718b31d8a01f76fc08e896a6d0d73dbeafc2621fe0...
695+
md5 e5828c564f71fea3a12dde8bd5d27063 README.rst
696+
ripemd160 ef6886c3b68cb34a44f9ca9336f3cd0732600a84 README.rst
697+
sha1 7bae8076a5771865123be7112468b79e9d78a640 README.rst
698+
sha512 65cfb1cf719b851b4aea5a7f5388068687b1fdfd290817a... README.rst
699+
whirlpool eaccf718b31d8a01f76fc08e896a6d0d73dbeafc2621fe0... README.rst
668700
669701
You can also specify which algorithm to use. In such case, the output is
670702
only the value of the calculated hash:
671703
672704
$ habu.hasher -a md5 README.rst
673-
e5828c564f71fea3a12dde8bd5d27063
705+
e5828c564f71fea3a12dde8bd5d27063 README.rst
674706
675707
Options:
676708
-a [md5|sha1|sha256|sha512|ripemd160|whirlpool]
@@ -893,6 +925,59 @@ Options:
893925
```
894926

895927

928+
## habu.nmap.open
929+
930+
931+
``` {.sourceCode .bash}
932+
Usage: habu.nmap.open [OPTIONS] SCANFILE
933+
934+
Read an nmap report and print the open ports.
935+
936+
Print the ports that has been resulted open reading the generated nmap
937+
output.
938+
939+
You can use it to rapidly reutilize the port list for the input of other
940+
tools.
941+
942+
Supports and detects the 3 output formats (nmap, gnmap and xml)
943+
944+
Example:
945+
946+
# habu.nmap.open portantier.nmap
947+
22,80,443
948+
949+
Options:
950+
-p [tcp|udp|sctp] The protocol (default=tcp)
951+
--help Show this message and exit.
952+
```
953+
954+
955+
## habu.nmap.ports
956+
957+
958+
``` {.sourceCode .bash}
959+
Usage: habu.nmap.ports [OPTIONS] SCANFILE
960+
961+
Read an nmap report and print the tested ports.
962+
963+
Print the ports that has been tested reading the generated nmap output.
964+
965+
You can use it to rapidly reutilize the port list for the input of other
966+
tools.
967+
968+
Supports and detects the 3 output formats (nmap, gnmap and xml)
969+
970+
Example:
971+
972+
# habu.nmap.ports portantier.nmap
973+
21,22,23,80,443
974+
975+
Options:
976+
-p [tcp|udp|sctp] The protocol (default=tcp)
977+
--help Show this message and exit.
978+
```
979+
980+
896981
## habu.ping
897982

898983

@@ -1116,6 +1201,39 @@ Options:
11161201
```
11171202

11181203

1204+
## habu.tcpscan-ng
1205+
1206+
1207+
``` {.sourceCode .bash}
1208+
Usage: habu.tcpscan-ng [OPTIONS] IP
1209+
1210+
TCP Port Scanner.
1211+
1212+
Print the ports that generated a response with the SYN flag or (if show
1213+
use -a) all the ports that generated a response.
1214+
1215+
It's really basic compared with nmap, but who is comparing?
1216+
1217+
Example:
1218+
1219+
# habu.tcpscan -p 22,23,80,443 -s 1 45.77.113.133
1220+
22 S -> SA
1221+
80 S -> SA
1222+
443 S -> SA
1223+
1224+
Options:
1225+
-p TEXT Ports to use (default: 80) example: 20-23,80,135
1226+
-i TEXT Interface to use
1227+
-f TEXT Flags to use (default: S)
1228+
-s TEXT Time between probes (default: send all together)
1229+
-t INTEGER Timeout for each probe (default: 2 seconds)
1230+
-a Show all responses (default: Only containing SYN flag)
1231+
-v Verbose output
1232+
-l TEXT Load session from file
1233+
--help Show this message and exit.
1234+
```
1235+
1236+
11191237
## habu.tcpscan
11201238

11211239

habu/cli/cmd_nmap_open.py

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env python3
2+
3+
import re
4+
import sys
5+
6+
import click
7+
8+
9+
def detect_format(data):
10+
if data.startswith('<?xml version="1.0" encoding="UTF-8"?>'):
11+
return 'xml'
12+
13+
lines = data.split('\n')
14+
15+
if lines[1].startswith('Host'):
16+
return 'gnmap'
17+
18+
if lines[1].startswith('Nmap scan report'):
19+
return 'nmap'
20+
21+
return 'unknown'
22+
23+
24+
def parse_format_xml(data, protocol):
25+
26+
# <port protocol="tcp" portid="21"><state state="closed"
27+
28+
line_regex_str = r'<port protocol="{}" portid="(?P<port>\d+)"><state state="open"'.format(protocol)
29+
line_regex = re.compile(line_regex_str)
30+
31+
ports = []
32+
33+
for line in data.split('\n'):
34+
m = line_regex.match(line)
35+
if m:
36+
ports.append(m.group(1))
37+
38+
return ','.join(ports)
39+
40+
41+
42+
def parse_format_nmap(data, protocol):
43+
44+
line_regex_str = r'(?P<port>\d+)/{}\s+open'.format(protocol)
45+
line_regex = re.compile(line_regex_str)
46+
47+
ports = []
48+
49+
for line in data.split('\n'):
50+
m = line_regex.match(line)
51+
if m:
52+
ports.append(m.group(1))
53+
54+
return ','.join(ports)
55+
56+
57+
58+
def parse_format_gnmap(data, protocol):
59+
60+
line_regex_str = r'(?P<port>\d+)/open/{}'.format(protocol)
61+
line_regex = re.compile(line_regex_str)
62+
63+
ports = []
64+
65+
for line in data.split('\n'):
66+
if 'Ports:' not in line:
67+
continue
68+
69+
content = line.split('Ports: ')[1]
70+
for c in content.split(','):
71+
c = c.strip()
72+
m = line_regex.match(c)
73+
if m:
74+
ports.append(m.group(1))
75+
76+
return ','.join(ports)
77+
78+
79+
80+
@click.command()
81+
@click.argument('scanfile', type=click.File())
82+
@click.option('-p', 'protocol', default='tcp', type=click.Choice(['tcp', 'udp', 'sctp']), help='The protocol (default=tcp)')
83+
def cmd_nmap_open(scanfile, protocol):
84+
"""Read an nmap report and print the open ports.
85+
86+
Print the ports that has been resulted open reading the generated nmap output.
87+
88+
You can use it to rapidly reutilize the port list for the input of other tools.
89+
90+
Supports and detects the 3 output formats (nmap, gnmap and xml)
91+
92+
Example:
93+
94+
\b
95+
# habu.nmap.open portantier.nmap
96+
22,80,443
97+
"""
98+
99+
data = scanfile.read()
100+
fmt = detect_format(data)
101+
102+
if fmt not in ['xml', 'nmap', 'gnmap']:
103+
print('Unknown file format.', file=sys.stdout)
104+
return 1
105+
106+
if fmt == 'nmap':
107+
result = parse_format_nmap(data, protocol)
108+
elif fmt == 'gnmap':
109+
result = parse_format_gnmap(data, protocol)
110+
elif fmt == 'xml':
111+
result = parse_format_xml(data, protocol)
112+
113+
print(result, end='')
114+
115+
return True
116+
117+
118+
if __name__ == '__main__':
119+
cmd_nmap_open()

0 commit comments

Comments
 (0)