분류 전체보기

    [LOS] Level2 cobolt 풀이

    Level2 : cobolt GET 방식으로 id와 pw를 입력받고, db에서 id와 pw가 각각 일치하는 레코드의 id를 select 한다. 이때, select 된 id가 admin이면 문제가 풀린다. id 부분은 admin을 입력해주면 되면 쉽게 True를 만들 수 있지만, admin에 해당하는 pw는 알 수 없다. mysql에서 한줄 주석은 '#' 이기 때문에 id를 입력 후 싱글쿼터로 닫고, 그 뒤 구문을 다 주석처리 하는 것이다. 그러면 pw를 몰라도 pw의 조건식을 무효화 시킬 수 있고, id값만 인증하면서 문제를 풀 수 있다. '?id=admin'#' '#'를 입력했지만 쿼리문에서는 '#'문자가 사라지는 것을 보면 필터링을 거치는 것 같다. '#'가 인코딩 되면 ASCII로 %23이기 때문에..

    [LOS] Level1 gremlin 풀이

    LOS(Lord of SQL Injection) : https://los.rubiya.kr/gate.php SQL Injection 공격에 대해 공부할 수 있다. Level1 : gremlin php 코드가 나온다. 빨간 박스를 보면 id와 pw를 GET 방식으로 받아오는 것을 알 수 있고, 초록 박스에서 query를 db에 질의하여 결과값이 있다면 문제를 해결할 수 있을 것으로 보인다. 먼저, GET방식으로 아무 값이나 넣어본다. 다음 사진과 같이 URL 주소 맨 뒤에 '?id=1&pw=1'를 입력한다. * ?는 URL주소 뒤에 변수를 지정할 수 있도록 구분하고, &는 변수와 또 다른 변수의 값을 넣어줄때 변수를 구분해준다. 엔터를 누르면 쿼리문의 where에 GET 방식으로 값이 입력된 것을 알 수 ..

    (Baekjoon) 백준 11729 - Python - 하노이 탑 이동 순서

    def hanoi(n, a, b, c): if n == 1: print(a, c) return hanoi(n-1, a, c, b) print(a, c) hanoi(n-1, b, a, c) n = int(input()) print(2**n-1) hanoi(n, 1, 2, 3) * 코드는 간단하지만, 알고리즘 이해는 좀 걸린 것 같다.

    (Baekjoon) 백준 10828 - Python - 스택

    N = int(input()) stack = [] for _ in range(N): c = input().split(' ') if c[0] == 'push': stack.append(int(c[1])) elif c[0] == 'pop': if len(stack) == 0: print(-1) else: print(stack.pop()) elif c[0] == 'size': print(len(stack)) elif c[0] == 'empty': if len(stack) == 0: print(1) else: print(0) elif c[0] == 'top': if len(stack) == 0: print(-1) else: print(stack[-1]) * 이 코드로 제출하면 시간 초과가 나게 되는데, inpu..

    (Baekjoon) 백준 9012 - Python - 괄호

    T = int(input()) for _ in range(T): underflow = 0 stack = [] line = list(input()) for word in line: if word == '(': stack.append(word) elif word == ')': if len(stack) == 0: underflow = 1 break stack.pop() if len(stack) == 0 and underflow != 1: print('YES') else: print('NO')

    (Baekjoon) 백준 2263 - Python - 트리의 순회

    def recursion(Inorder, Postorder): if len(Inorder) 2: Preorder_root = Postorder.pop(-1) Inorder_index = Inorder.index(Preorder_root) Postorder_left = Postorder[:Inorder_index] Postorder_right = Postorder[Inorder_index:] Inorder_le..

    (CodeUp) 코드업 1930 - Python - SuperSum

    dic = {} def superSum(k, n): if k == 0: return n find = str(k) + '-' + str(n) if find in dic: return dic[find] sum = 0 for i in range(1, n+1): sum += superSum(k-1, i) dic[find] = sum return dic[find] while(True): try: k, n = input().split(' ') k = int(k) n = int(n) print(superSum(k, n)) except EOFError: break

    (Baekjoon) 백준 9095 - Python - 1, 2, 3 더하기

    dic = {0:0, 1:1} def recursion(n): if n in dic: return dic[n] if n < 1: return 0 dic[n] = recursion(n-1) + recursion(n-2) + recursion(n-3) return dic[n] T = int(input()) arr = list() for i in range(T): arr.append(int(input())) for i in arr: print(recursion(i+1))