etc.git


etc

~ scripts and random things
git clone https://github.com/djnnvx/etc.git
log | files | refs | archive

commit e088619d90ef539cd9930fc30a21b84757078851
parent c04b7f34cebf6b8390507bbe3c051c8533de427b
Author: djnn <[email protected]>
Date: Tue, 9 Jul 2024 13:00:51 +0200

feat(bins): adding `dump_proc` utility little script to dump the proc/{pid} filesystem

Diffstat:
Abin/crt.sh | 27+++++++++++++++++++++++++++
Abin/dump_proc | 39+++++++++++++++++++++++++++++++++++++++
Rtools/twft -> bin/twft | 0
Rscripts/install-fuzzing-tools.sh -> one-time-scripts/install-fuzzing-tools.sh | 0
Dtools/crt.sh | 25-------------------------

5 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/bin/crt.sh b/bin/crt.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+# little wrapper to query crt.sh service and retrieve a list of domain names
+# usage:
+# crt.sh djnn.sh
+
+set -euo pipefail
+
+
+check_installed () {
+    # check if dependencies are installed
+    for i in "${@}"; do
+        which "${i}" >/dev/null || { echo "[!] error: please install ${1}." && exit 1 ; }
+    done
+}
+
+
+check_installed jq curl sed sort uniq
+
+[ "${#}" -eq 0 ] && { echo "[!] one argument is required" && head -n 5 ${0} && exit 1 ; }
+
+search="$(curl -s "https://crt.sh?q=${1}&output=json")"
+
+echo "${search}" | jq ".[].common_name,.[].name_value" | \
+    cut -d'"' -f2 | sed 's/\\n/\n/g' | sed 's/\*.//g' | \
+    sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | \
+    sort | uniq
diff --git a/bin/dump_proc b/bin/dump_proc
@@ -0,0 +1,39 @@
+#!/usr/bin/env python2
+
+# TODO(djnn): rewrite this in python3
+
+import ctypes, re, sys
+
+c_ptrace = ctypes.CDLL("libc.so.6").ptrace
+c_pid_t = ctypes.c_int32
+c_ptrace.argtypes = [ctypes.c_int, c_pid_t, ctypes.c_void_p, ctypes.c_void_p]
+
+def ptrace(attach, pid):
+    op = ctypes.c_int(16 if attach else 17) #PTRACE_ATTACH or PTRACE_DETACH
+    c_pid = c_pid_t(pid)
+    null = ctypes.c_void_p()
+    err = c_ptrace(op, c_pid, null, null)
+    if err != 0: raise SysError, 'ptrace', err
+
+def maps_line_range(line):
+    m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line)
+    return [int(m.group(1), 16), int(m.group(2), 16), m.group(3)]
+
+def cat_proc_mem(pid):
+    ptrace(True, int(pid))
+    maps_file = open("/proc/" + pid + "/maps", 'r')
+    ranges = map(maps_line_range, maps_file.readlines())
+    maps_file.close()
+    mem_file = open("/proc/" + pid + "/mem", 'r', 0)
+    for r in ranges:
+        if r[2] == 'r':
+            mem_file.seek(r[0])
+            chunk = mem_file.read(r[1] - r[0])
+            print chunk,
+
+    mem_file.close()
+    ptrace(False, int(pid))
+
+if __name__ == "__main__":
+    for pid in sys.argv[1:]:
+        cat_proc_mem(pid)
diff --git a/tools/twft b/bin/twft
diff --git a/scripts/install-fuzzing-tools.sh b/one-time-scripts/install-fuzzing-tools.sh
diff --git a/tools/crt.sh b/tools/crt.sh
@@ -1,25 +0,0 @@
-#!/usr/bin/env bash
-
-# little wrapper to query crt.sh service and retrieve a list of domain names
-# usage:
-# crt.sh djnn.sh
-
-set -euo pipefail
-
-
-check_installed () {
-    # check if dependency is installed
-    which "${1}" >/dev/null || { echo "[!] error: please install ${1}." && exit 1 ; }
-}
-
-
-check_installed jq curl sed sort uniq
-
-[ "${#}" -eq 0 ] && { echo "[!] one argument is required" && head -n 5 ${0} && exit 1 ; }
-
-search="$(curl -s "https://crt.sh?q=${1}&output=json")"
-
-echo "${search}" | jq ".[].common_name,.[].name_value" | \
-    cut -d'"' -f2 | sed 's/\\n/\n/g' | sed 's/\*.//g' | \
-    sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | \
-    sort | uniq