-
Notifications
You must be signed in to change notification settings - Fork 0
/
osms_finder.py
107 lines (78 loc) · 2.99 KB
/
osms_finder.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
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
from argparse import ArgumentParser
from urllib.parse import urlparse
from bs4 import BeautifulSoup
import requests
import socket
def getArguments():
parser = ArgumentParser()
parser.add_argument('--target', help='Enter a target site address')
parser.add_argument('--ipFile', help='Ip address file')
parser.add_argument('--notSub', help='Enter the site without a subdomain')
return parser.parse_args()
def ipLister(file: str) -> list:
try:
with open(file, 'r') as f:
ips = [i.strip() for i in f.readlines()
if i not in ('', '\n') and not i.isspace()]
return ips
except FileNotFoundError:
print('[!]-> File not found! <-[!]')
quit()
def linkFinder(site: str) -> set:
r = requests.get(site, headers=headers).text
d = BeautifulSoup(r, 'html.parser')
all_links = d.find_all('a')
all_links = [i.attrs['href'] for i in all_links]
checked_links = set()
for i in all_links:
if i.startswith(('https://', 'http://')):
i = urlparse(i)
i = i.scheme + '://' + i.netloc
if notSub not in i: checked_links.add(i)
return checked_links
def showLinks(fLinks: dict) -> None:
for (link, ip) in fLinks.items():
print(link.ljust(50) + " | " + ip)
def scanner(links: set, ips: list) -> None:
sameServerLinks = {}
for siteaddr in links:
try:
tIp = socket.gethostbyname(urlparse(siteaddr).netloc)
except socket.error:
print(f'[*]-> I can\'t connect to site {siteaddr}')
continue
if tIp in ips:
sameServerLinks[siteaddr] = tIp
if len(sameServerLinks.keys()) == 0:
print('\n[!]-> No other site found on the same server!! <-[!]\n')
else:
showLinks(sameServerLinks)
def main() -> None:
global notSub, ip_list, headers
try:
args = getArguments()
target = args.target
notSub = args.notSub.strip('/')
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
}
except AttributeError:
print("\n[!]-> Please use parameters! <-[!]")
else:
if target:
if (notSub and (notSub in target)) and (target.startswith(('https://', 'http://'))):
try:
ip_list = [socket.gethostbyname(urlparse(target).netloc)]
except socket.error:
print('[!]-> Check the given site or your internet connection <-[!]')
quit()
if args.ipFile:
ip_list.extend(ipLister(args.ipFile))
scanner(linkFinder(target), ip_list)
else:
print('\n[!]-> Please, check the notSub parameter value! <-[!]\n')
else:
print(
'\n[!]-> Please enter a valid site address, Ex: https://www.exsitemysite.com\n')
if __name__ == '__main__':
main()