-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.py
executable file
·71 lines (59 loc) · 2.4 KB
/
server.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
#!/usr/bin/python
# Nuke My LUKS - server
# A simple network-based panic button designed to overwrite the LUKS header
# with random data and reboot the computer in case of an emergency situation.
#
# IMPORTANT: This will make *impossible* to recover any data stored in the disk
# even if the password is known. Use this code with precaution.
#
# by Julio Cesar Fort - [email protected]
import sys
import socket
import select
import os.path
import platform
import base64
import ConfigParser
from subprocess import Popen, PIPE
try:
from bcrypt import hashpw, gensalt
except ImportError as err:
print "[!] Error importing 'bcrypt': %s" % err
sys.exit()
DEFAULT_PORT = 1337
ERROR = -1
NUKEMYLUKS_CMD = './nukemyluks.sh'
def main():
# check if we're running this code on Linux or not
if 'Linux' not in platform.system():
print "[!] Error: this can only run on Linux."
sys.exit(ERROR)
# create a broadcast UDP receving socket
receiving_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
receiving_socket.bind(('<broadcast>', DEFAULT_PORT))
receiving_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
receiving_socket.setblocking(0)
while True:
result = select.select([receiving_socket], [], [])
msg = result[0][0].recv(1024)
if msg.startswith("nukemyluks_"):
try:
configparser = ConfigParser.ConfigParser()
configparser.read('config.ini')
hashed_secret = configparser.get('config', 'password_hash')
except Exception as err:
print "[!] Error reading config file: %s" % err
# TODO: send error message back containing the server IP
sys.exit()
secret = base64.b64decode(msg[len("nukemyluks_"):])
if hashed_secret == hashpw(secret, hashed_secret):
if not os.path.isfile(NUKEMYLUKS_CMD):
print "[!] Cannot execute the %s (No such file)" % NUKEMYLUKS_CMD
sys.exit(ERROR)
cmd_output = Popen([NUKEMYLUKS_CMD], stdout=PIPE,
stdin=PIPE, stderr=PIPE)
STDOUT, STDERR = cmd_output.communicate()
print STDOUT
# TODO: send a success message back containing the server IP
if __name__ == '__main__':
main()