summaryrefslogtreecommitdiff
path: root/html/cgi-bin/webshell.cgi
blob: 6598d372cd84b9ea1e2612754f7a5d5338e1146a (plain)
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
#!/usr/bin/env python3

# après avoir lancé le serveur : python3 -m http.server --cgi
# placer le script (rendu exécutable) dans /cgi-bin... 

import cgi
import os

form = cgi.FieldStorage()
cmd = form.getvalue('command')
user = os.getlogin()
host = os.environ.get('SERVER_NAME')
pwd = os.environ.get('PWD')

print("Content-Type: text/html; charset=UTF-8\n\n")
print ("""
<html>
<head>
<title>Web shell</title>
</head>
<body>
<h1>Web shell</h1>
<p>Entrez votre commande : </p>
<form action=''>
<input type='text' name='command' id='command' />
<input type='submit' value='submit' />
</form>""")
if cmd : 
    print("<pre style='display:inline-block;min-width:50em;padding:1em;background-color:black;color:white'>")
    print(f"{user}@{host}:{pwd}$ {cmd}\n{os.popen(cmd).read()}")
    print("</pre>")
print("""
<script>document.getElementById("command").focus()</script>
</body>
</html>""")