forked from infobyte/faraday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
67 lines (56 loc) · 1.63 KB
/
common.py
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
'''
Faraday Penetration Test IDE
Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/)
See the file 'doc/LICENSE' for the license information
'''
import hashlib
import uuid
import time
import socket
import struct
import sys
import requests
def sha1OfFile(filepath):
with open(filepath, 'rb') as f:
return hashlib.sha1(f.read()).hexdigest()
def sha1OfStr(strvalue):
return hashlib.sha1(strvalue).hexdigest()
def get_hash(parts):
return hashlib.sha1("._.".join(parts)).hexdigest()
def new_id():
return uuid.uuid4()
def get_macaddress(host):
if sys.platform in ['linux','linux2']:
with open("/proc/net/arp") as fh:
for line in fh:
fields = line.strip().split()
if fields[0] == host:
return fields[3]
else:
return None
def gateway():
ip=""
if sys.platform in ['linux','linux2']:
with open("/proc/net/route") as fh:
for line in fh:
fields = line.strip().split()
if fields[1] != '00000000' or not int(fields[3], 16) & 2:
continue
ip=socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))
mac=get_macaddress(ip)
return [str(ip),str(mac)]
elif sys.platform in ['darwin']:
return None
else:
return None
def checkSSL(uri):
"""
This method checks SSL validation
It only returns True if the certificate is valid
and the http server returned a 200 OK
"""
try:
res = requests.get(uri, timeout=5)
return res.ok
except Exception:
return False