모의해킹

cURL 명령어 정리

우와해커 2020. 8. 3. 23:00

cURL

- Web Security Testing Cookbook.pdf 공부내용

 

Using cURL, we can ignore JavaScript and browserbased behaviors and focus exclusively on what the server-side logic does or does not do

 

 

장점

- 브라우저 제약 받지 않음

- 자바스크립트 무시가능

- 서버사이드 로직에 영향을 받는지 여부를 파악할 수 있음.

 

단점

- URL인코딩 지원안해서 직접 해야됨 /my site => /my%20site

- 테스트할 때, 서버가 user-agent에 따라 다른 내용을 출력하는걸 감안해야 됨

 


제일 유용할거 같은 명령어 세트

curl -v -i http://naver.com

 

 

명령어 정리

 

-i: 응답 헤더 값도 포함해서 보고싶을 때 사용.

-I: 간단히 응답 헤더만 확인하고 싶을 때 사용.

-k: 불안전한 인증성 암호통신 접근 (개발 or 테스트 페이지에 유용)

-L: 리다이렉트 따라가기

-e: Referer 지정

-A: 에이전트 지정

-g: 데이터를 지정한 get 메서드 요청(생략시 디폴트 값)

(viewState같은)

-v: 디버거, 자세히 보기

 

 

-d: 데이터를 지정한 post 메서드 요청  (@파일명.txt), 대량의 파라미터 값을 파일에 미리 저장 후 불러와서 사용가능

curl -d "birthyear=1905&press=%20OK%20" www.hotmail.com/when/junk.cgi

 

 

curl -X OPTIONS -v -i http://naver.com

-X: 요청 메소드 헤더 지정: OPTIONS, TRACE 등 다른 요청 지정가능

 

 

curl -H "Host:" http://mysite.com

-H: 헤더 항목 내용 커스터마이징해서 요청 가능

 

 

-T: 간단 파일 업로드

curl -T uploadfile www.uploadhttp.com/receive.cgi

 

 

파일폼, POST 파일 업로드
curl -F upload=@localfilename -F press=OK [URL]

 

 

 

curl -b cookies.txt -c cookies.txt -d userid=admin -d passwd=1234 'http://naver.com/login.do'

1.-d: POST로 로그인 요청

2.-c: 세션 획득 후 쿠키 업데이트

3.-b: 저장된 쿠키파일 사용

 

 

업로드 테스트

curl -F file='photo.jsp;filetype=image/jpeg' -F param2=data1 'https://naver.com/photos/upload.do'

 

-F: 파일 업로드 파라미터 지정 (바운더리 자동으로 생성해줌), filetype은 OPTIONAL

 

 

-o '파일명': 파일저장

 숫자,갯수 지정 '#1#2.html' 'http://example.com/CATID=[0-9][0-9]'

 이름지정 '#1.html' 'http://example.com?color={red,blue,green}'

 

 

curl로 쉘 스크립트 만들때 팁

 

파이어폭스 > temperdata > exportXML 기능 사용

 

 

더 해볼 과제: cURL을 쉘로 자동 스크립트 짜기

 

 


추가 자료

 

http methods                    curl -XTRACE  <url>
x-forwarded-for                 curl -H "X-Forwarded-For: 10.0.0.1" <url> 
basic authentication            curl -u <user>:<password> <url>
post form                       curl -XPOST --form "b=4_1" <url>         
cookie                          curl --cookie "PHPSESSID=5ved46gn34dopkjhstrrfgdkk1;" <url>
cookie files (save & send)      curl -c /tmp/cookie.txt -b /tmp/cookie.txt <url>
set user-agent                  curl -A "Mozilla" <url>
referer                         curl -H "Referer: https://www.cnn.com"
json                            curl -XPOST -H "Content-Type: application/json" -d "[[\"create\",
                                {\"type\":\"trial\",\"name\":\"bug\"}]] <url>
silent                          curl -s <url>
verbose                         curl -v <url>
ignore certifikate issues       curl -k <url>
follow redircts                 curl -L <url>
redirect output into file       curl -o <file> <url>
curl with proxy                 curl -x <proxy>:<port> <url>
curl SSL V3                     curl -k -v --sslv3 <url> 
curl max time (4 seconds)       curl -m4 <url>
file upload                     curl -XPOST -F ul=30000 -F location=/tmp/upload-form-data.txt 
                                -F userfile=@/tmp/upload-file.txt <url>
shell-shock                     curl -k -L -H 'User-Agent: () { :;}; curl -L  <return-server>;'  <url>
post data from file             curl -data '@<filename>' <url>
curl output response time       curl -o /dev/null -w%{time_connect}:%{time_starttransfer}%{time_total} <url>
curl output request size        curl -o /dev/null -w%{size_request} %{size_upload} <url> 
curl output http status code    curl -o /dev/null -w%%{http_code} <url>
curl resolve ip from other dns  curl --resolve "www.cnn.com:80:8.8.8.8" http://www.cnn.com