Made ALTCODE-TRANSCODER. (#373)

* Response to Hak5 2506

* A random 'e' ended up on line 58.

Line is blank now like it is supposed to be.

* Created readme

STAGE2 made more sense when it was STAGE1/STAGE2, but the transcoding is a special stage and the typing is stage 2 since the transcoding had to be done first.
This commit is contained in:
G4te-Keep3r 2019-02-13 14:41:46 -06:00 committed by Darren Kitchen
parent b1309229cc
commit 502576d7ed
5 changed files with 395 additions and 0 deletions

View File

@ -0,0 +1,256 @@

§
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
Ç
ü
é
â
ä
à
å
ç
ê
ë
è
ï
î
ì
Ä
Å
É
æ
Æ
ô
ö
ò
û
ù
ÿ
Ö
Ü
¢
£
¥
ƒ
á
í
ó
ú
ñ
Ñ
ª
º
¿
¬
½
¼
¡
«
»
α
ß
Γ
π
Σ
σ
µ
τ
Φ
Θ
Ω
δ
φ
ε
±
÷
°
·
²
 

View File

@ -0,0 +1,44 @@
import sys, binascii, string
ansiDict = {}
def getDict(SWITCH_POSITION):
#read ansiDict.txt file to get the bytes for the widows altcodes (ascii 128-255)
altcode = 0
with open('/root/udisk/payloads/'+SWITCH_POSITION+'/ansiDict.txt', 'rb') as f:
for line in f:
line = str(binascii.hexlify(line))
while line.endswith('0a') or line.endswith('0d'):
line = ''.join(line.split('0a')[:-1])
line = ''.join(line.split('0d')[:-1])
line = binascii.unhexlify(line)
if len(line) > 0:
ansiDict[str(binascii.hexlify(line))] = str(altcode)
altcode += 1
def main(SWITCH_POSITION):
localDir = '/root/udisk/payloads/' + SWITCH_POSITION + '/'
lineCount = 0
with open(localDir + 'payload.txt', 'a+') as payload:
with open(localDir + 'img.txt', 'rb') as img:
for line in img:
lineCount += 1
index = 0
while index < len(line)-1:
c = line[index]
if c in string.printable:
#normal character
payload.write('QUACK STRING'+c+'\n')
index += 1
else:
#altcode
key = binascii.hexlify(line[index:index+3])
payload.write('QUACK ALTCODE '+ansiDict[key]+'\n')
index += 3
payload.write('QUACK ENTER\n')
payload.write('LED FINISH')
print lineCount, 'lines processed'
if __name__ == '__main__':
getDict(sys.argv[1])
main(sys.argv[1])

View File

@ -0,0 +1,12 @@
░░░▓████░░░░░░███░▒░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░
░░░████▒░░░░░░░███░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓░▓░▓░░
░░░████░░░░░░░████░░░░▒░░░░░░░░░▒░░░░██░░▓▓▓▓▓▓░░░░░░░░░░░░
░░▓███████████████░░░█████░░░░███░░▒███░▓▓▓▓▓▓▒▓▓▓▓▓▓▓▓░░░░
░░██████░████████░░░██████░░░████▓███░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░
░░░███░░░░░░░████░▒███░████░░████████░▓▓▓▓▓▓░░░░▓▓▓▓▓▓▓░░░░
░░████░░░░░░░████░███▓▓▓███░░███░░████░░░░░░░░░▓▓▓▓▓▓▓▒░░░░
░█████░░░░░░░███░██████████▒░███░░░█▒▓▓▓▓▓░░░░░▓▓▓▓▓▓▓░░░░░
░████░░░░░░░████▓██░░░░░░██████▓░░░░▓▓▓▓▓▓▓░░░▓▓▓▓▓▓▓░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓░▓▓▓▓▓▓░░░▓▓▓▓▓▓▓░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓░▓░░░░░░░░░░░░

View File

@ -0,0 +1,57 @@
# ANSI Art Transcoder
# Author: G4te_Keep3r
# Props: Crackruckles, Hak5Darren
# Target: Windows 95+
# Category: General
LED SETUP
ATTACKMODE HID
GET SWITCH_POSITION
#Does the image need to be processed?
if [ -e /root/udisk/payloads/$SWITCH_POSITION/img.txt ]; then
#Alert user of compilation
QUACK GUI r
QUACK DELAY 500
QUACK STRING "cmd"
QUACK ENTER
QUACK DELAY 1000
QUACK STRING echo [YOUR ART HERE] is being transcoded. Please wait...
QUACK ENTER
### Future update: check file size, at some threshold display progress bar during transcode below
LED SPECIAL
#Python script takes ASCII codes to QUACK ALTCODE
#Should work for regular characters too...but I finally got this to work and do not want to spend another 4+ days debuggin right now. L8r tho.
QUACK STRING echo $(echo -e $(python /root/udisk/payloads/$SWITCH_POSITION/art2bunny.py $SWITCH_POSITION))
QUACK ENTER
QUACK DELAY 1000
QUACK STRING "TIMEOUT /T 10 && exit"
QUACK ENTER
LED R B
( sleep 10 ; reboot ) &
#The sleep time here and above for cmd are probably way longer than needed.
rm /root/udisk/payloads/$SWITCH_POSITION/img.txt
#sync might not be needed, but was having trouble with changes saving to drive before reboot
sync
QUACK DELAY 1000
LED FINISH
#Instead of exit could use an else below, but I think this looks cleaner and the python script does not have to close the if
exit
fi
#Art it up!
LED STAGE2
QUACK GUI r
QUACK DELAY 500
QUACK STRING "cmd /K copy con ansi.txt&exit"
QUACK ENTER
QUACK DELAY 1000
#Codes added after here (leave blank line below this or first code will be missed)

View File

@ -0,0 +1,26 @@
# ALTCODE TRANSCODER
* Author: G4te_Keep3r
* Props: Crackruckles, Hak5Darren
* Demo: Hak5 episode 2506
* Target: Windows 95+
* Category: General
## Description
Takes a text file containing ansi art and converts it to QUACKs so the bunny can be loud. In the future it might look for image files to convert to ansi art first. The code is still a little rough and not the most efficient, but working with windows only character set in linux problematic.
## Requirements
img.txt in the switch directory for the bunny to eat. If you want to change to a different image later, you will need to reset payload.txt as the lines of QUACK ALTCODE ### are added at the bottom of the payload. The encoding of img.txt can be an issue. It seemed to work best with unicode or utf-8, but it might work just fine with any format. If it fails, try another format.
## STATUS
| LED | Status |
| ----------------- | --------------------------------------------- |
| SETUP | Setting attack mode, checking for image file |
| SPECIAL | Python script is transcoding |
| R B | Sleep/reboot command started and storage sync |
| FINISH | Will be rebooting any second |
| STAGE2 | Art is being typeed |
| FINISH | Done |