Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Tree/AVL
- Tree/AVL/Deletion
- CS/자료구조/Queue
- forensic
- reversing
- CS/자료구조/Singly_Linked_List
- Tree/Traversal
- ctf
- CS/자료구조/Priority_Queue
- CS/자료구조/Stack
- codeengn
- Tree/RBTree
- CS/자료구조/Circular_Queue
- Tree/BST
- Tree/Binary_Search_Tree
- tree
- Tree/Binary_Tree
- 리버싱
- Tree/AVL/Insertion
- Tree/RBTree/Deletion
- 코드엔진
- UTCTF
- Tree/RBTree/Insertion
- CS/자료구조/Doubly_Linked_List
- CS/자료구조/Circular_Linked_List
- CS/자료구조/Linked_List
Archives
- Today
- Total
SuperVingo
UTCTF 2021 Reversing Peeb Poob Write up 본문
728x90
Peeb Poob
ghidra 분석
undefined4 main(void)
{
size_t len;
char arr [32];
undefined4 local_14;
uint j;
int i;
local_14 = 0;
i = 0;
while (i < 0x20) {
arr[i] = '\0';
i = i + 1;
}
printf("Enter a string: \n");
fgets(arr,0x20,stdin);
encode(arr);
j = 0;
while( true ) {
len = strlen(arr);
if (len <= j) {
puts("Nice flag!");
return 0;
}
if (arr[j] != flag[j]) break;
j = j + 1;
}
puts("Wrong!");
/* WARNING: Subroutine does not return */
exit(-1);
}
void encode(char *str)
{
size_t len;
uint temp;
uint i;
i = 0;
while (len = strlen(str), i < len) {
temp = (uint)((int)i < 0);
temp = ((i ^ -temp) + temp & 3 ^ -temp) + temp;
if (temp < 4) {
switch(temp) {
case 0:
str[i] = str[i] ^ 0x21;
break;
case 1:
str[i] = str[i] ^ 7;
break;
case 2:
str[i] = str[i] ^ 0x23;
break;
case 3:
str[i] = str[i] ^ 5;
}
}
len = strlen(str);
if (i + 1 < len) {
str[i + 1] = str[i] ^ str[i + 1];
}
i = i + 1;
}
return;
}
함수 2개 발견
encode (0부터 시작)
1. 특정 연산으로 temp 구한 후, temp값에 의해 xor 연산
2. 다음 문자열을 xor연산된 값으로 미리 xor
3. 다음 문자열도 특정 연산으로 temp 구한 후, temp값에 의해 xor 연산
반복
decode (뒷자리부터 시작)
1. 특정 연산으로 temp 구한 후, temp값에 의해 xor 연산
2. 이전 문자열과 xor연산
3. 이전 문자열도 특정 연산으로 temp 구한 후, temp값에 의해 xor 연산
반복
특정 연산을 확인해보니
temp = (uint)((int)i < 0);
temp = ((i ^ -temp) + temp & 3 ^ -temp) + temp;
---------------------------------------------------------------
temp = 0;
temp = ((i ^ 0) + 0 & 3 ^ 0) + 0;
---------------------------------------------------------------
temp -> 0 1 2 3 0 1 2 3 0 1 2 3 . . .
i % 4와 같은 연산임
flag 배열 확인
Sol
flag = [0x54, 0x27, 0x62, 0x0b, 0x4b, 0x2b, 0x73, 0x14, 0x06, 0x32, 0x61, 0x3b, 0x78, 0x4f, 0x5c, 0x29, 0x57, \
0x20, 0x30, 0x06, 0x45, 0x1d, 0x4e, 0x7b, 0x6a, 0x0f, 0x51, 0x5e, 0x00, 0x00, 0x00, 0x00]
def encode(str):
for i in range(0, len(str)):
if(i % 4 == 0):
str[i] ^= 0x21
elif(i % 4 == 1):
str[i] ^= 0x07
elif(i % 4 == 2):
str[i] ^= 0x23
elif(i % 4 == 3):
str[i] ^= 0x05
if(i + 1 < len(str)):
str[i+1] ^= str[i]
def decode(str):
for i in range(len(str) - 1, -1, -1):
if(i % 4 == 0):
str[i] ^= 0x21
elif(i % 4 == 1):
str[i] ^= 0x07
elif(i % 4 == 2):
str[i] ^= 0x23
elif(i % 4 == 3):
str[i] ^= 0x05
if(i != 0):
str[i] ^= str[i-1]
for i in str[0:28]:
print(chr(i), end="")
decode(flag)
utflag{b33p_b00p_p33b_p00b}
728x90
'CaptureTheFlag[CTF] > UTCTF2021' 카테고리의 다른 글
UTCTF 2021 Crypto Small P Problem Write up (0) | 2021.03.17 |
---|---|
UTCTF 2021 Reversing Recur Write up (0) | 2021.03.17 |
UTCTF 2021 Misc Emoji Encryption Write up (0) | 2021.03.16 |
UTCTF 2021 Forensic OSINT Part 2 Write up (0) | 2021.03.16 |
UTCTF 2021 Forensic OSINT Part 1 Write up (0) | 2021.03.16 |