# tmap 0.1
# coded by thekingof9x <at> yandex . com
# fast multi-threaded port scanner which tunnels through tor.
# depends on the pysocks library: https://github.com/anorov/pysocks
# and of course tor: apt-get install tor
#
# do not use hostnames, may leak dns info. only use ip addresses.
#
# not happy with the privoxy + tor (exit relay only) + nmap config. i made this.
#
# usage:
# python tmap.py

import sys
import socks
import datetime
import threading
lock = threading.semaphore(value = 1)

#port of tor server
tor_port = 9050
#timeout. experiment with this.
timeout = 20
#port list to scan, ammend at will
ports = (21,22,23,80,443,1433,3306,8080)

def main():

if len(sys.argv) < 3:
print("\033[92m\n\t\t\ttmap 0.1\n\nfast multi-threaded port scanner which tunnels through tor.\n\n\033[0m")
print("single host scan:\npython " + sys.argv[0] + " -s 192.168.0.1\n")
print("/24 (class c) range scan:\npython " + sys.argv[0] + " -r 192.168.0\n")
print("list scan:\npython " + sys.argv[0] + " -l iplist.txt\n")
exit(0)

scan_type = sys.argv[1]
parameter = sys.argv[2]

filename = datetime.datetime.now().strftime("%h:%m_%d-%m-%y.tmap")
try:
log = open(filename, "a")
except:
pass

if scan_type == "-s":
host_scan(parameter, log)
elif scan_type == "-r":
range_scan(parameter, log)
elif scan_type == "-l":
list_scan(parameter, log)
else:
exit(1)

#main connect function
def connect(ip, port, log):
try:
s = socks.socksocket()
s.setproxy(socks.proxy_type_socks5, 'localhost', tor_port)
s.settimeout(timeout)
s.connect((ip, port))
output = ip + ":" + str(port)
lock.acquire() # lock/unlock to clean up screen output.
print(output)

try:
log.write(output + "\n")
except:
pass

except:
pass

finally:
lock.release()

def host_scan(ip, log):
ip = ip.strip()
for port in ports:
try:
t = threading.thread(target=connect, args=(ip, port, log))
t.start()
except:
pass

def range_scan(ip, log):
ip = ip.strip()
for i in range(1, 255):
ip_addr = ip + "." + str(i)
for port in ports:
try:
t = threading.thread(target=connect, args=(ip_addr, port, log))
t.start()
except:
pass

def list_scan(parameter, log):
try:
f = open(parameter, 'r')
except:
print("could not open file: " + parameter)
exit(1)

for ip in f:
ip = ip.strip()
for port in ports:
try:
t = threading.thread(target=connect, args=(ip, port, log))
t.start()
except:
pass

if __name__ == '__main__':
main()

comments
rss feed

no comments yet, be the first!
login or register to post a comment

follow on twitter follow us on twitter
follow on facebook follow us on facebook
view rss feeds subscribe to an rss feed

file archive:
march 2015