mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Merge remote-tracking branch 'origin/GP-6445_d-millar_connector_tests--SQUASHED'
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##
|
||||
#@title dbgeng (.ps1)
|
||||
#@title dbgeng
|
||||
#@image-opt env:OPT_TARGET_IMG
|
||||
#@desc <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>dbgeng</tt></h3>
|
||||
@@ -26,7 +26,6 @@
|
||||
#@icon icon.debugger
|
||||
#@help dbgeng#local
|
||||
#@depends Debugger-rmi-trace
|
||||
#@arg :file "Image" "The target binary executable image"
|
||||
#@env OPT_TARGET_IMG:file="" "Image" "The target binary executable image"
|
||||
#@env OPT_TARGET_ARGS:str="" "Arguments" "Command-line arguments to pass to the target"
|
||||
#@env OPT_PYTHON_EXE:file!="python" "Python command" "The path to the Python 3 interpreter. Omit the full path to resolve using the system PATH."
|
||||
|
||||
@@ -69,7 +69,7 @@ $answer = Check-Result-And-Prompt-Mitigation $sshproc @"
|
||||
It appears ghidradbg is missing from the remote system. This can happen if you
|
||||
forgot to install the required package. This can also happen if you installed
|
||||
the packages to a different Python environment than is being used by the
|
||||
remote's gdb.
|
||||
remote's dbgeng.
|
||||
|
||||
This script is about to offer automatic resolution. If you'd like to resolve
|
||||
this manually, answer no to the next question and then see Ghidra's help by
|
||||
|
||||
@@ -72,7 +72,7 @@ $answer = Check-Result-And-Prompt-Mitigation $sshproc @"
|
||||
It appears ghidradbg is missing from the remote system. This can happen if you
|
||||
forgot to install the required package. This can also happen if you installed
|
||||
the packages to a different Python environment than is being used by the
|
||||
remote's gdb.
|
||||
remote's dbgeng.
|
||||
|
||||
This script is about to offer automatic resolution. If you'd like to resolve
|
||||
this manually, answer no to the next question and then see Ghidra's help by
|
||||
|
||||
@@ -17,11 +17,6 @@
|
||||
|
||||
function Compute-Dbg-PipInstall-Args {
|
||||
$argvpart = $args -join ", "
|
||||
$arglist = @("$Env:OPT_PYTHON_EXE -c `"")
|
||||
$arglist+=("import os, sys, runpy")
|
||||
$arglist+=("sys.argv=['pip', 'install', '--force-reinstall', $argvpart]")
|
||||
$arglist+=("os.environ['PIP_BREAK_SYSTEM_PACKAGE']='1'")
|
||||
$arglist+=("runpy.run_module('pip', run_name='__main__')")
|
||||
|
||||
$arglist = @("$Env:OPT_PYTHON_EXE -c `"import os, sys, runpy; sys.argv=['pip', 'install', '--force-reinstall', $argvpart]; os.environ['PIP_BREAK_SYSTEM_PACKAGE']='1'; runpy.run_module('pip', run_name='__main__')`"")
|
||||
return $arglist
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
cxn = os.getenv('GHIDRA_TRACE_RMI_ADDR')
|
||||
target = os.getenv('OPT_TARGET_PID')
|
||||
args = os.getenv('OPT_ATTACH_FLAGS')
|
||||
@@ -52,6 +53,11 @@ def append_paths():
|
||||
def main():
|
||||
append_paths()
|
||||
# Delay these imports until sys.path is patched
|
||||
try:
|
||||
import ghidradbg
|
||||
except Exception as e:
|
||||
print(e)
|
||||
exit(253)
|
||||
from ghidradbg import commands as cmd
|
||||
from pybag.dbgeng import core as DbgEng
|
||||
from ghidradbg.hooks import on_state_changed
|
||||
@@ -82,5 +88,7 @@ if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except SystemExit as x:
|
||||
if x.code == 253:
|
||||
exit(253)
|
||||
if x.code != 0:
|
||||
print(f"Exited with code {x.code}")
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
cxn = os.getenv('GHIDRA_TRACE_RMI_ADDR')
|
||||
target = os.getenv('OPT_TARGET_IMG')
|
||||
args = os.getenv('OPT_TARGET_ARGS')
|
||||
@@ -55,6 +56,11 @@ def main():
|
||||
return
|
||||
|
||||
# Delay these imports until sys.path is patched
|
||||
try:
|
||||
import ghidradbg
|
||||
except:
|
||||
print(e)
|
||||
exit(253)
|
||||
from ghidradbg import commands as cmd
|
||||
from pybag.dbgeng import core as DbgEng
|
||||
from ghidradbg.hooks import on_state_changed
|
||||
@@ -92,5 +98,7 @@ if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except SystemExit as x:
|
||||
if x.code == 253:
|
||||
exit(253)
|
||||
if x.code != 0:
|
||||
print(f"Exited with code {x.code}")
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##
|
||||
#@title gdb via ssh ((remote=cmd shell)
|
||||
#@title gdb via ssh (cmd shell)
|
||||
#@image-opt arg:1
|
||||
#@desc <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>gdb</tt> via <tt>ssh</tt> to a remote Windows machine</h3>
|
||||
@@ -30,7 +30,7 @@
|
||||
#@enum Endian:str auto big little
|
||||
#@arg :str "Image" "The target binary executable image on the remote system"
|
||||
#@env OPT_TARGET_ARGS:str="" "Arguments" "Command-line arguments to pass to the target"
|
||||
##@env OPT_SSH_PATH:file="ssh" "ssh command" "The path to ssh on the local system. Omit the full path to resolve using the system PATH."
|
||||
#@env OPT_SSH_PATH:file="ssh" "ssh command" "The path to ssh on the local system. Omit the full path to resolve using the system PATH."
|
||||
#@env OPT_HOST:str="localhost" "[User@]Host" "The hostname or user@host"
|
||||
#@env OPT_REMOTE_PORT:int=12345 "Remote Trace RMI Port" "A free port on the remote end to receive and forward the Trace RMI connection."
|
||||
#@env OPT_EXTRA_SSH_ARGS:str="" "Extra ssh arguments" "Extra arguments to pass to ssh. Use with care."
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
$Env:OPT_OS_WINDOWS = $true
|
||||
$arglist = @("")
|
||||
$arglist += ("cat > .\.gdbinit")
|
||||
$arglist += ("cat > .\ghidra.gdbinit")
|
||||
$sshargs = Compute-Ssh-Args $arglist True
|
||||
|
||||
$image = ($args[0]).Replace("\", "\\")
|
||||
@@ -60,7 +60,7 @@ Replace('$OPT_START_CMD', $Env:OPT_START_CMD)`
|
||||
|
||||
$arglist = @("")
|
||||
$arglist += ("$Env:OPT_GDB_PATH")
|
||||
$arglist += ("-q")
|
||||
$arglist += ("-q", "-x", ".\ghidra.gdbinit")
|
||||
$sshargs = Compute-Ssh-Args $arglist True
|
||||
|
||||
$sshproc = Start-Process -FilePath ssh -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait -PassThru
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##
|
||||
#@title gdb via ssh (to cmd)
|
||||
#@title gdb via ssh (cmd shell)
|
||||
#@image-opt arg:1
|
||||
#@desc <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>gdb</tt> via <tt>ssh</tt></h3>
|
||||
@@ -64,7 +64,7 @@ function rewrite-gdbinit() {
|
||||
|
||||
function launch-gdb-ssh-init() {
|
||||
local -a sshargs
|
||||
compute-ssh-args true "cat > .\.gdbinit"
|
||||
compute-ssh-args true "cat > .\ghidra.gdbinit"
|
||||
|
||||
"${sshargs[@]}"
|
||||
}
|
||||
@@ -73,7 +73,7 @@ rewrite-gdbinit | launch-gdb-ssh-init
|
||||
|
||||
function launch-gdb-ssh() {
|
||||
local -a sshargs
|
||||
compute-ssh-args true "gdb -q"
|
||||
compute-ssh-args true "gdb -q -x .\ghidra.gdbinit"
|
||||
|
||||
"${sshargs[@]}"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
python
|
||||
def try_import():
|
||||
try:
|
||||
import ghidragdb
|
||||
except Exception as e:
|
||||
gdb.execute("exit(253)")
|
||||
end
|
||||
|
||||
|
||||
set pagination off
|
||||
set confirm off
|
||||
show version
|
||||
python import ghidragdb
|
||||
python if not 'ghidragdb' in locals(): exit(253)
|
||||
python try_import()
|
||||
set architecture $OPT_ARCH
|
||||
set endian $OPT_ENDIAN
|
||||
file '$OPT_TARGET_IMG'
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##
|
||||
#@title lldb via ssh (remote=cmd shell)
|
||||
#@title lldb via ssh (cmd shell)
|
||||
#@image-opt arg:1
|
||||
#@desc <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>lldb</tt> via <tt>ssh</tt> to a remote Windows machine</h3>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##
|
||||
#@title lldb via ssh (to cmd)
|
||||
#@title lldb via ssh (cmd shell)
|
||||
#@image-opt arg:1
|
||||
#@desc <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>lldb</tt> via <tt>ssh</tt></h3>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##
|
||||
#@title x64dbg (.ps1)
|
||||
#@title x64dbg
|
||||
#@image-opt env:OPT_TARGET_IMG
|
||||
#@desc <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>x64dbg</tt></h3>
|
||||
|
||||
@@ -53,6 +53,7 @@ function Compute-Python-Args {
|
||||
}
|
||||
|
||||
$arglist+=($Env:OPT_TARGET_PID)
|
||||
$arglist+=($Env:OPT_X64DBG_EXE)
|
||||
|
||||
return $arglist
|
||||
}
|
||||
@@ -69,10 +70,10 @@ $sshproc = Start-Process -FilePath $sshargs[0] -ArgumentList $sshargs[1..$ssharg
|
||||
|
||||
$version = Get-Ghidra-Version
|
||||
$answer = Check-Result-And-Prompt-Mitigation $sshproc @"
|
||||
It appears ghidradbg is missing from the remote system. This can happen if you
|
||||
It appears ghidraxdbg is missing from the remote system. This can happen if you
|
||||
forgot to install the required package. This can also happen if you installed
|
||||
the packages to a different Python environment than is being used by the
|
||||
remote's gdb.
|
||||
remote's x64dbg.
|
||||
|
||||
This script is about to offer automatic resolution. If you'd like to resolve
|
||||
this manually, answer no to the next question and then see Ghidra's help by
|
||||
@@ -93,14 +94,14 @@ are copied and installed.
|
||||
|
||||
NOTE: Automatic resolution will cause this session to terminate. When it has
|
||||
finished, try launching again.
|
||||
"@ "Would you like to install 'ghidradbg>=$version'?"
|
||||
"@ "Would you like to install 'ghidraxdbg>=$version'?"
|
||||
|
||||
if ($answer) {
|
||||
Write-Host "Copying Wheels to $Env:OPT_HOST"
|
||||
Mitigate-Scp-PyModules "Debugger-rmi-trace" "<SELF>"
|
||||
|
||||
Write-Host "Installing Wheels into python"
|
||||
$arglist = Compute-Dbg-PipInstall-Args "'-f'" "os.environ['HOME']" "'ghidradbg>=$version'"
|
||||
$arglist = Compute-X64dbg-PipInstall-Args "'-f'" "os.environ['HOME']" "'ghidraxdbg>=$version'"
|
||||
$sshargs = Compute-Ssh-Args $arglist False
|
||||
Start-Process -FilePath $sshargs[0] -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ function Compute-Python-Args {
|
||||
if ("$Env:OPT_TARGET_IMG" -ne "") {
|
||||
$arglist+=($Env:OPT_TARGET_IMG)
|
||||
}
|
||||
if ("$Env:OPT_X64DBG_EXE" -ne "") {
|
||||
$arglist+=($Env:OPT_X64DBG_EXE)
|
||||
}
|
||||
if ("$Env:OPT_TARGET_DIR" -ne "") {
|
||||
$arglist+=($Env:OPT_TARGET_DIR)
|
||||
}
|
||||
@@ -78,10 +81,10 @@ $sshproc = Start-Process -FilePath $sshargs[0] -ArgumentList $sshargs[1..$ssharg
|
||||
|
||||
$version = Get-Ghidra-Version
|
||||
$answer = Check-Result-And-Prompt-Mitigation $sshproc @"
|
||||
It appears ghidradbg is missing from the remote system. This can happen if you
|
||||
It appears ghidraxdbg is missing from the remote system. This can happen if you
|
||||
forgot to install the required package. This can also happen if you installed
|
||||
the packages to a different Python environment than is being used by the
|
||||
remote's gdb.
|
||||
remote's x64dbg.
|
||||
|
||||
This script is about to offer automatic resolution. If you'd like to resolve
|
||||
this manually, answer no to the next question and then see Ghidra's help by
|
||||
@@ -102,14 +105,14 @@ are copied and installed.
|
||||
|
||||
NOTE: Automatic resolution will cause this session to terminate. When it has
|
||||
finished, try launching again.
|
||||
"@ "Would you like to install 'ghidradbg>=$version'?"
|
||||
"@ "Would you like to install 'ghidraxdbg>=$version'?"
|
||||
|
||||
if ($answer) {
|
||||
Write-Host "Copying Wheels to $Env:OPT_HOST"
|
||||
Mitigate-Scp-PyModules "Debugger-rmi-trace" "<SELF>"
|
||||
|
||||
Write-Host "Installing Wheels into python"
|
||||
$arglist = Compute-Dbg-PipInstall-Args "'-f'" "os.environ['HOME']" "'ghidradbg>=$version'"
|
||||
$arglist = Compute-X64dbg-PipInstall-Args "'-f'" "os.environ['HOME']" "'ghidraxdbg>=$version'"
|
||||
$sshargs = Compute-Ssh-Args $arglist False
|
||||
Start-Process -FilePath $sshargs[0] -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ def parse_parameters():
|
||||
if argc >= 3:
|
||||
cxn = sys.argv[1]
|
||||
target = sys.argv[2]
|
||||
os.environ['OPT_X64DBG_EXE'] = sys.argv[3]
|
||||
return True
|
||||
print("Error: expected (cxn, target, initdir, ...)")
|
||||
return False
|
||||
@@ -48,6 +49,11 @@ def append_paths():
|
||||
def main():
|
||||
append_paths()
|
||||
# Delay these imports until sys.path is patched
|
||||
try:
|
||||
import ghidraxdbg
|
||||
except:
|
||||
print(e)
|
||||
exit(253)
|
||||
from ghidraxdbg import commands as cmd
|
||||
from ghidraxdbg.hooks import on_state_changed
|
||||
from ghidraxdbg.util import dbg
|
||||
@@ -77,5 +83,7 @@ if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except SystemExit as x:
|
||||
if x.code == 253:
|
||||
exit(253)
|
||||
if x.code != 0:
|
||||
print(f"Exited with code {x.code}")
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
cxn = os.getenv('GHIDRA_TRACE_RMI_ADDR')
|
||||
target = os.getenv('OPT_TARGET_IMG')
|
||||
args = os.getenv('OPT_TARGET_ARGS')
|
||||
@@ -32,12 +31,13 @@ def parse_parameters():
|
||||
if argc >= 3:
|
||||
cxn = sys.argv[1]
|
||||
target = sys.argv[2]
|
||||
os.environ['OPT_X64DBG_EXE'] = sys.argv[3]
|
||||
if argc > 4:
|
||||
initdir = sys.argv[3]
|
||||
initdir = sys.argv[4]
|
||||
else:
|
||||
initdir = "."
|
||||
if argc > 4:
|
||||
args = sys.argv[4]
|
||||
if argc > 5:
|
||||
args = sys.argv[5]
|
||||
else:
|
||||
args = ""
|
||||
return True
|
||||
@@ -63,6 +63,11 @@ def main():
|
||||
return
|
||||
|
||||
# Delay these imports until sys.path is patched
|
||||
try:
|
||||
import ghidraxdbg
|
||||
except Exception as e:
|
||||
print(e)
|
||||
exit(253)
|
||||
from ghidraxdbg import commands as cmd
|
||||
from ghidraxdbg.hooks import on_state_changed
|
||||
from ghidraxdbg.util import dbg
|
||||
@@ -96,5 +101,7 @@ if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except SystemExit as x:
|
||||
if x.code == 253:
|
||||
exit(253)
|
||||
if x.code != 0:
|
||||
print(f"Exited with code {x.code}")
|
||||
|
||||
@@ -17,11 +17,6 @@
|
||||
|
||||
function Compute-X64dbg-PipInstall-Args {
|
||||
$argvpart = $args -join ", "
|
||||
$arglist = @("$Env:OPT_PYTHON_EXE -c `"")
|
||||
$arglist+=("import os, sys, runpy")
|
||||
$arglist+=("sys.argv=['pip', 'install', '--force-reinstall', $argvpart]")
|
||||
$arglist+=("os.environ['PIP_BREAK_SYSTEM_PACKAGE']='1'")
|
||||
$arglist+=("runpy.run_module('pip', run_name='__main__')")
|
||||
|
||||
$arglist = @("$Env:OPT_PYTHON_EXE -c `"import os, sys, runpy; sys.argv=['pip', 'install', '--force-reinstall', $argvpart]; os.environ['PIP_BREAK_SYSTEM_PACKAGE']='1'; runpy.run_module('pip', run_name='__main__')`"")
|
||||
return $arglist
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ function Compute-Ssh-Args {
|
||||
$cmdline = $arglist -join " " -replace "`"", "\`""
|
||||
|
||||
$sshargs = @("`"$Env:OPT_SSH_PATH`"")
|
||||
$sshargs+=("-t")
|
||||
# NB: Is this needed? It break target==Windows.
|
||||
# $sshargs+=("-t")
|
||||
if ($forward) {
|
||||
$sshargs+=("-R$Env:OPT_REMOTE_PORT`:$Env:GHIDRA_TRACE_RMI_ADDR")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user