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
class
RC4:
def
__init__(
self
, key)
-
>
None
:
self
.key
=
key
self
.S
=
0
self
.__rc4_init__()
def
__rc4_init__(
self
):
S
=
[i
for
i
in
range
(
256
)]
j
=
0
for
i
in
range
(
256
):
j
=
(
2
*
j
+
S[i]
+
key[i
%
len
(key)])
%
256
S[i], S[j]
=
S[j], S[i]
self
.S
=
S
def
rc4_encrypt(
self
, plain)
-
>
list
:
i
=
0
j
=
0
cipher
=
[]
cnt
=
0
for
p
in
plain:
p
=
(p
+
256
-
cnt
%
0xd
)
%
256
cnt
+
=
1
i
=
(i
+
j)
%
256
j
=
(j
+
self
.S[i])
%
256
self
.S[i],
self
.S[j]
=
self
.S[j],
self
.S[i]
tmp
=
self
.S[(
self
.S[i]
+
self
.S[j]
+
j)
%
256
]
k
=
p ^ tmp
cipher.append(k)
return
cipher
key
=
[
0x5D
,
0x42
,
0x62
,
0x29
,
0x3
,
0x36
,
0x47
,
0x41
,
0x15
,
0x36
]
data
=
[
0xF7
,
0x2E
,
0x34
,
0xF0
,
0x72
,
0xCF
,
0x5E
,
0x0A
,
0xBB
,
0xEC
,
0xB1
,
0x2B
,
0x70
,
0x88
,
0x88
,
0xED
,
0x46
,
0x38
,
0xDB
,
0xDA
,
0x6C
,
0xBD
,
0xD4
,
0x06
,
0x77
,
0xF2
,
0xCF
,
0x56
,
0x88
,
0xC6
,
0x31
,
0xD2
,
0xB7
,
0x5A
,
0xC1
,
0x42
,
0xB0
,
0xF4
,
0x48
,
0x37
,
0xF5
,
0x2C
,
0xF5
,
0x58
]
rc4
=
RC4(key)
plain
=
rc4.rc4_encrypt(data)
print
(''.join(
map
(
chr
,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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import
ctypes
from
time
import
*
from
ctypes
import
*
from
ctypes
import
wintypes
from
hashlib
import
md5
class
_STARTUPINFO(Structure):
_fields_
=
[
(
'cb'
, c_ulong),
(
'lpReserved'
, c_char_p),
(
'lpDesktop'
, c_char_p),
(
'lpTitle'
, c_char_p),
(
'dwX'
, c_ulong),
(
'dwY'
, c_ulong),
(
'dwXSize'
, c_ulong),
(
'dwYSize'
, c_ulong),
(
'dwXCountChars'
, c_ulong),
(
'dwYCountChars'
, c_ulong),
(
'dwFillAttribute'
, c_ulong),
(
'dwFlags'
, c_ulong),
(
'wShowWindow'
, c_ushort),
(
'cbReserved2'
, c_ushort),
(
'lpReserved2'
, c_char_p),
(
'hStdInput'
, c_ulong),
(
'hStdOutput'
, c_ulong),
(
'hStdError'
, c_ulong)]
class
_PROCESS_INFORMATION(Structure):
_fields_
=
[
(
'hProcess'
, c_void_p),
(
'hThread'
, c_void_p),
(
'dwProcessId'
, c_ulong),
(
'dwThreadId'
, c_ulong)]
StartupInfo
=
_STARTUPINFO()
ProcessInfo
=
_PROCESS_INFORMATION()
key1
=
bytes(md5(b
'bin1bin1bin1'
).hexdigest().encode())
file
=
open
(
'bin1'
,
'rb'
).read()
arr
=
range
(
len
(
file
))()
open
(
'bin1'
,
'wb'
).write(bytes(arr))
sleep(
0
)
bet
=
ctypes.windll.kernel32.CreateProcessA(b
'bin1'
, ctypes.c_int(
0
), ctypes.c_int(
0
), ctypes.c_int(
0
), ctypes.c_int(
0
), ctypes.c_int(
0
), ctypes.c_int(
0
), ctypes.c_int(
0
), byref(StartupInfo), byref(ProcessInfo))
ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(ProcessInfo.hProcess), ctypes.c_int(
-
1
))
open
(
'bin1'
,
'wb'
).write(
file
)
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
using namespace std;
void btea(uint32_t
*
v,
int
n, uint32_t const key[
4
]) {
uint32_t y, z,
sum
;
unsigned p, rounds, e;
if
(n >
1
) {
/
*
Coding Part
*
/
rounds
=
/
*
6
+
*
/
52
/
n;
sum
=
0
;
z
=
v[n
-
1
];
do {
sum
+
=
DELTA;
e
=
(
sum
>>
2
) &
3
;
for
(p
=
0
; p < n
-
1
; p
+
+
) {
y
=
v[p
+
1
];
z
=
v[p]
+
=
MX;
}
y
=
v[
0
];
z
=
v[n
-
1
]
+
=
MX;
}
while
(
-
-
rounds);
}
else
if
(n <
-
1
) {
/
*
Decoding Part
*
/
n
=
-
n;
rounds
=
/
*
6
+
*
/
52
/
n;
sum
=
rounds
*
DELTA;
y
=
v[
0
];
do {
e
=
(
sum
>>
2
) &
3
;
for
(p
=
n
-
1
; p >
0
; p
-
-
) {
z
=
v[p
-
1
];
y
=
v[p]
-
=
MX;
}
z
=
v[n
-
1
];
y
=
v[
0
]
-
=
MX;
}
while
((
sum
-
=
DELTA) !
=
0
);
}
}
int
main()
{
uint32_t const key[
4
]
=
{
0x4B5F
,
0xDEAD
,
0x11ED
,
0xB3CC
};
uint32_t data[
11
]
=
{
0xCC45699D
,
0x683D5352
,
0xB8BB71A0
,
0xD3817AD
,
0x7547E79E
,
0x4BDD8C7C
,
0x95E25A81
,
0xC4525103
,
0x7049B46F
,
0x5417F77C
,
0x65567138
};
uint32_t
*
sent
=
data;
/
/
btea(sent,
11
, key);
/
/
printf(
"coded:%x %x\n"
, sent[
0
], sent[
1
]);
btea(sent,
-
11
, key);
/
/
printf(
"decoded:%x %x\n"
, sent[
0
], sent[
1
]);
for
(
int
i
=
0
; i <
11
; i
+
+
) {
for
(
int
j
=
0
; j <
4
; j
+
+
)
{
printf(
"%c"
, sent[i] &
0xff
);
sent[i] >>
=
8
;
}
}
return
0
;
}
/
/
DASCTF{
7eb20cb2
-
deac
-
11ed
-
ae42
-
94085339ce84
}