实现思路
通过sftp使得两端文件同步,windows端下发编译命令,linux编译后发送exe给windows,windows使用本地gdb调试发送过来的exe,添加文件映射,使得gdb找到windows端的源码
双方的免密登录
-
tips:Windows openssh服务器的config
PubkeyAuthentication yes #Match Group administrators # AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
-
客户端生成密钥对将公钥拷贝到服务端的authorized_keys即可,两者都需要相互登录:
-
window作为客户端,linux作为服务端
-
linux作为服务端,windows作为客户端
-
gdb的安装
gdb安装再windows端
vscode插件sftp安装(sftp.json)
sftp.json: { "name": "KaliServer", "host": "192.168.72.162", "protocol": "sftp", "port": 5022, "username": "root", "remotePath": "/root/Havoc_dbg/c_demo", "uploadOnSave": true, "useTempFile": false, "openSsh": false } 我这里的5022端口是开放额外的ssh服务(linux端开放的)
task.json
-
发送给linux编译指令
-
拷贝linux的exe文件
{ "version": "2.0.0", "tasks": [ { "label": "cross_compile", "type": "shell", "command": "ssh -p 9722 root@192.168.72.162 \"/root/Havoc_dbg/teamserver_proj/data/x86_64-w64-mingw32-cross/bin/x86_64-w64-mingw32-gcc ~/Havoc_dbg/c_demo/main.c -g -o /tmp/a2.exe \" ", // "command": "ssh -p 9722 root@192.168.72.162 \"/root/Havoc_dbg/teamserver_proj/data/x86_64-w64-mingw32-cross/bin/x86_64-w64-mingw32-gcc ~/Havoc_dbg/c_demo/main.c -g -o /tmp/a.exe\" && scp -o StrictHostKeyChecking=no /tmp/a.exe andy@DESKTOP-T89LSP5:F:\\6.phrase_six\\havoc\\c_demo_exe\\.build \" ", "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] }, { "label": "copy_file", "type": "shell", "command": "ssh -p 9722 root@192.168.72.162 \" scp /tmp/a2.exe andy@DESKTOP-T89LSP5:F:/6.phrase_six/havoc/c_demo_exe/.build/a2.exe \" ", // "command": "ssh -p 9722 root@192.168.72.162 \"/root/Havoc_dbg/teamserver_proj/data/x86_64-w64-mingw32-cross/bin/x86_64-w64-mingw32-gcc ~/Havoc_dbg/c_demo/main.c -g -o /tmp/a.exe\" && scp -o StrictHostKeyChecking=no /tmp/a.exe andy@DESKTOP-T89LSP5:F:\\6.phrase_six\\havoc\\c_demo_exe\\.build \" ", "dependsOn": "cross_compile", // 等待 `task1` 完成后再执行 "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] }, ], }
Launch.json
-
设置拷贝过来的exe为调试目标(program变量)
-
设置gdb路径(miDebuggerPath)
-
设置文件映射(exe在linux下编译,路径会是linux下的,通过sourceFileMap能改成windows下的)
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "F:/6.phrase_six/havoc/c_demo_exe/.build/a2.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "copy_file",
"miDebuggerPath": "F:/6.phrase_six/GBD/GDB-Windows-Binaries-master/gdb.exe", // gdb路径
"sourceFileMap":
{
"/root/Havoc_dbg/c_demo": "${workspaceFolder}/"
},
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
编译调试测试
除了不能进入系统静态库外,与正常调试无任何差别:
-
调试前编译,两端同步使得调试信息和源码保持同步准确