-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexecute.py
More file actions
53 lines (28 loc) · 872 Bytes
/
execute.py
File metadata and controls
53 lines (28 loc) · 872 Bytes
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
import sys, os
# check if the number of arguments supplied is 3 or more
if len(sys.argv) < 3:
print('expecting exactly two arguments: username and password')
print("usage: python execute.py username password")
exit()
# the code to be exported
code = r"""
import sys, os, ctypes
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
os.system("net User %s %s")
else:
ctypes.windll.shell32.ShellExecuteW(
None, u"runas", sys.executable, __file__, None, 1)
"""
# format the code with arguments
code = code % (sys.argv[1], sys.argv[2])
# directory of the output file
directory = os.path.dirname(os.path.realpath(__file__))
output_file = os.path.join(directory, 'code.py')
# write code to file
with open(output_file, 'w') as file:
file.write(code)