전체 381

[Webhacking.kr] old-03 / Challenge 3

노노그램이라는 게임이 화면에 뜬다. 노노그램은 숫자에 맞게 색칠하는 퍼즐 게임인데 숫자가 여러 개면 사이에 공백이 한 칸 이상 있다는 뜻이다. 칸을 클릭해보니 색칠이 되었다. 폰으로 노노그램하던 짬바를 발휘해 풀어보았다. 5x5라 금방 풀 수 있었다. 성공하면 다음과 같은 인풋창이 나타난다. 아무거나 입력하고 submit을 누르니 name과 answer, ip가 차례대로 나타났다. admin을 입력해봤다. answer가 바뀔 줄 알았는데 바뀌지 않았다. 디코딩해봐도 특정한 값은 안나왔다. name에 sql injection을 시도해보았다. 넣은 값이 그대로 보여진다. answer에도 sql injection을 시도해보자. answer에 ' or 1=1--을 넣고 제출하면 query error!가 뜬다. ..

[HackerRank] Trees > Tree : Height of a Binary Tree

https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree/problem 바이너리 트리의 높이를 구하는 문제다. int height(Node* root) { // Write your code here. int r = 0, l = 0; if(root->right!=nullptr){ r = height(root->right); r++; } if(root->left!=nullptr){ l = height(root->left); l++; } if(r>l) return r; else return l; } 왼쪽의 높이와 오른쪽의 높이를 구할 변수 l과 r을 설정해 주었다. if문으로 다음 노드가 nullptr이 아니라면 길이를 구해준다. r과 l중 긴 쪽..

[HackerRank] Implementation > Cats and a Mouse

https://www.hackerrank.com/challenges/cats-and-a-mouse/problem 두 마리의 고양이와 한 마리의 쥐가 있다. 위치를 계산해 쥐를 더 빨리 잡을 수 있는 고양이를 출력한다. 거리가 같으면 고양이들이 싸우느라 쥐가 도망가므로 Mouse C를 출력한다. x = Cat A, y = Cat B, z = Mouse C char* catAndMouse(int x, int y, int z) { char *str = (char*)malloc(10); int a = x-z, b = y-z; if(ab이면 Cat B, a

[Webhacking.kr] old-24 / challenge 24

해당 문제에 접속하면 자신의 ip와 agent가 나와있는 것을 알 수 있다. Wrong IP!라는 문구가 뜬다. 아래에 있는 view-source url로 들어가 소스코드를 확인해보았다. extract($_SERVER); extract($_COOKIE); php에서 extract 함수는 배열 속의 키값을 변수화 시켜주는 함수이다. 여기서는 $_COOKIE가 변수화 될 것이다. https://bbolmin.tistory.com/53 if($REMOTE_ADDR){ $ip = htmlspecialchars($REMOTE_ADDR); $ip = str_replace("..",".",$ip); $ip = str_replace("12","",$ip); $ip = str_replace("7.","",$ip); $i..

[HackerRank] Implementation > Bill Division

https://www.hackerrank.com/challenges/bon-appetit/problem Anna와 Brian이 밥을 먹었다. 계산할 때 Anna가 먹지 않은 음식의 값을 뺀 나머지를 Brian과 나누는데, 돈이 잘 계산됐는지 확인하면 된다. 배열 bill에 음식의 값들이 저장되고, Anna가 먹지 않은 음식의 인덱스는 k에 저장된다. b는 Brian이 Anna에게 청구한 금액인데, 맞으면 Bon Appetit를, 틀리면 Brian이 청구한 금액 - Anna가 낼 금액을 계산해서 출력한다. void bonAppetit(int bill_count, int* bill, int k, int b) { int anna = 0; for(int i=0; i

[HackerRank] Linked Lists > Insert a Node at the Tail of a Linked List

https://www.hackerrank.com/challenges/insert-a-node-at-the-tail-of-a-linked-list/problem 연결리스트의 마지막에 노드를 삽입하는 문제다. SinglyLinkedListNode* insertNodeAtTail(SinglyLinkedListNode* head, int data) { if (head == NULL) { return create_singly_linked_list_node(data); } SinglyLinkedListNode *node = head; while (node->next != NULL) { node = node->next; } node->next = create_singly_linked_list_node(data); r..