Skip to content

Commit 9045146

Browse files
authored
Update crab.py
1 parent 5c4f48a commit 9045146

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/crab.py

+47
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import socket
66
import time
77
from scapy.all import *
8+
import json
89

910
args = sys.argv[1:]
1011

@@ -16,6 +17,41 @@
1617
\____/_/ \__,_/_.___/ By NotAidan.
1718
''')
1819

20+
def generate_new_filename(filename):
21+
base, ext = os.path.splitext(filename)
22+
counter = 1
23+
while os.path.exists(f"{base} ({counter}){ext}"):
24+
counter += 1
25+
return f"{base} ({counter}){ext}"
26+
27+
28+
def censysHostLookup(host):
29+
headers = {
30+
'Accept': 'application/json',
31+
}
32+
33+
params = {
34+
'q': f'{host}',
35+
}
36+
37+
response = requests.get(
38+
'https://search.censys.io/api/v2/hosts/search',
39+
params=params,
40+
headers=headers,
41+
42+
# PUT YOUR API ID AND API KEY HERE IF YOU WANT TO USE CENSYS
43+
auth=(os.getenv('CENSYS_API_ID', 'API_ID_HERE'), os.getenv('CENSYS_API_SECRET', 'API_SECRET_HERE')),
44+
)
45+
46+
filename = "CensysData.txt"
47+
new_filename = generate_new_filename(filename)
48+
f = open(new_filename, "a+")
49+
f.write(json.dumps(response.json(), indent=2))
50+
f.close()
51+
52+
print(f"Check CensysData.txt for the logs or go to https://search.censys.io/search?resource=hosts&sort=RELEVANCE&per_page=25&virtual_hosts=EXCLUDE&q={host}")
53+
54+
1955

2056
# os detection using ttl values in a icmp request
2157
def icmpOSD(host):
@@ -97,18 +133,26 @@ def fastportscan(host, timeout):
97133
if (args[0] == "-h"):
98134
print('''Usage: python crab.py [Options] {Target}
99135
-h: Shows this menu
136+
100137
-sA: Port Scan All - Casual port scan. Scans every port on a given host.
101138
Usage: python crab.py -sA [host] [time out in seconds]
102139
Example: python crab.py -sA google.com 0.5
140+
103141
-sC: Port scan common - Fastest port scan. Only scans from a range of 1 - 1024
104142
Usage: python crab.py -sC [host] [time out in seconds]
105143
Example: python crab.py -sC google.com 0.5
144+
106145
-pD: Ping Detection - this command uses icmp requests and analyzes the ttl to derive an OS.
107146
--- WARNING --- ping detection might not work unless ran with elevated permissions
108147
Usage: python crab.py -pD [host]
109148
Example: python crab.py -pD 1.1.1.1
149+
110150
-i: Info - Get Basic information on a given Host/IP. Its basically a IP scanner.
151+
111152
-w: whois - Runs a whois search on a given Host
153+
154+
-cS: Censys Lookup - This will run a given domain/host against Censys and obtain good information. REMEMBER TO PLACE YOUR API ID AND API SECRET INTO THE MAIN FILE (crab.py) AROUND LINE 36
155+
Usage: python crab.py -cS [host]
112156
''')
113157
if (args[0] == "-i"):
114158
iplookup(args[1])
@@ -120,6 +164,9 @@ def fastportscan(host, timeout):
120164
fastportscan(args[1], args[2])
121165
if (args[0] == "-pD"):
122166
icmpOSD(args[1])
167+
if (args[0] == "-cS"):
168+
censysHostLookup(args[1])
123169

124170
except IndexError:
125171
print("Invalid args. Use [-h] for help")
172+

0 commit comments

Comments
 (0)