Files
NeuroSploit/neurosploit-rs/tools/re/NsDangerousCalls.java
T
CyberSecurityUP 54e8b13035 feat: pluggable LLM providers, kernel/binary recon, iterative tool-calling, mobile/binary pipeline
Model integration:
- neurosploit key add/list/remove/detect: identify a provider from its key,
  list real callable models, save it — CLI, REPL and web console share one
  detector/keystore.
- custom_providers.rs: register any OpenAI-compatible endpoint under its own
  name (mycorp:<model>) with no source change or rebuild; several can coexist.
- Added deepseek-v4-1-flash-1017, Venice AI, vLLM and LM Studio providers.
- Fixed --sandbox/--stealth/--neo4j/--engagement being silently dropped by
  mobile/container/host/network/ad/cloud/greybox/tui/aitest (only `run` wired
  them before).

Recon depth:
- codeindex.rs: whole-repo indexing for whitebox review (functions, routes,
  call graph, sources/sinks/sanitizers) with cross-file attack-flow tracing,
  replacing the old first-200-files slice. Multi-pass per-agent context within
  a budget, plus a variant/circumvention-review doctrine for every SAST agent.
- kernel_recon.rs: deterministic Linux kernel facts over an authorized SSH
  session (version, modules, SUID surface, sysctls) for the LLM to reason from.
- winbin_harvest.rs: pulls third-party Windows driver/service binaries off an
  authorized host over SMB and runs them through the same deep binary pass.
- re_tools.rs: embedded read-only radare2/Ghidra/IDA/Frida helper scripts and
  headless drivers, shared by the mobile/binary and Windows-harvest pipelines.
- 38 new mobile/iOS/Android/native-binary research agents (agents_md/mobile/
  was empty before — `neurosploit mobile` ran zero agents).
- artifact.rs: resolve a local path or URL, classify by magic bytes, hash.
- profile.rs: network vs AD vs cloud:<provider> vs web agent-set restriction;
  `run` now defaults to web-only agents (--all-agents lifts it).

Agentic capability / opsec:
- agentic_tools.rs: a real iterative tool-calling loop (call a tool, read its
  actual output, decide the next one) replacing the one-shot batch picker;
  wired into the existing recon tool round.
- noise_governor.rs: the per-host rate/jitter governor existed but was never
  called anywhere — wired it into the new tool-calling loop under --stealth.
- credtest.rs: credentials surfaced by the attack-chain loop are now actually
  tested (SSH/SMB/WinRM/HTTP-basic) between rounds instead of left for the
  model to maybe act on; a verified one becomes a confirmed-foothold fact for
  the next round.
- teamboard.rs: exploit agents in the same wave see each other's leads
  (credentials, endpoints) as they land, with IDs so a finding can cite the
  lead it was chained from (chains_from is now actually parsed and recorded).
- poc_gate.rs: lints PoC scripts for known false-positive patterns (success
  printed in an error handler, unconditional success, self-injection, a script
  that reimplements the bug instead of exercising the target) and lowers
  confidence instead of trusting the script blindly.
- taint.rs: detects and strips "poison the AI agent" decoy comments (the
  SpikeStrip pattern — a random hex key followed by a fabricated CVE/route)
  regardless of payload wording, by their structural fingerprint.
- recon_compact.rs: semantic compaction of recon JSON (halves the largest
  array, keeps every key) instead of a hard character truncation that silently
  dropped the tail of the reply.

751 tests passing; release build clean.
2026-11-28 14:18:53 -03:00

128 lines
5.7 KiB
Java

// NeuroSploit Ghidra headless script: callers of unsafe functions, with decompiled context.
//
// Usage (headless):
// analyzeHeadless <projdir> ns -import <binary> -scriptPath <this dir> \
// -postScript NsDangerousCalls.java <out.jsonl> -deleteProject
//
// Read-only. One JSON object per (sink, calling function): the sink, the caller's
// name and entry address, the call-site address and the decompiled caller, so an
// analyst (or agent) can check whether the arguments are attacker-controlled and
// bounded instead of trusting that an import exists.
//
// @category NeuroSploit
import ghidra.app.decompiler.DecompInterface;
import ghidra.app.decompiler.DecompileResults;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionManager;
import ghidra.program.model.symbol.Reference;
import ghidra.program.model.symbol.ReferenceManager;
import ghidra.program.model.symbol.Symbol;
import ghidra.program.model.symbol.SymbolIterator;
import ghidra.program.model.symbol.SymbolTable;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
public class NsDangerousCalls extends GhidraScript {
private static final String[] SINKS = {
// unbounded or length-trusting copies and formatting
"strcpy", "strcat", "sprintf", "vsprintf", "gets", "scanf", "sscanf", "fscanf",
"memcpy", "memmove", "strncpy", "strncat", "alloca", "realloc", "read", "recv", "recvfrom", "fread",
// execution and loading
"system", "popen", "execl", "execv", "execve", "execvp", "dlopen",
"WinExec", "ShellExecuteA", "ShellExecuteW", "CreateProcessA", "CreateProcessW",
"LoadLibraryA", "LoadLibraryW",
// format-string consumers
"printf", "fprintf", "syslog", "snprintf",
// temp-file races
"tmpnam", "tempnam", "mktemp"
};
private static String esc(String s) {
StringBuilder b = new StringBuilder();
for (char c : s.toCharArray()) {
switch (c) {
case '"': b.append("\\\""); break;
case '\\': b.append("\\\\"); break;
case '\n': b.append("\\n"); break;
case '\r': break;
case '\t': b.append("\\t"); break;
default: if (c >= 0x20) b.append(c);
}
}
return b.toString();
}
private static String clip(String code, int lines) {
String[] parts = code.split("\n");
StringBuilder b = new StringBuilder();
for (int i = 0; i < parts.length && i < lines; i++) b.append(parts[i]).append("\n");
if (parts.length > lines) b.append("/* ... ").append(parts.length - lines).append(" more lines */");
return b.toString();
}
@Override
protected void run() throws Exception {
String[] args = getScriptArgs();
File out = new File(args.length > 0 ? args[0] : "ns_dangerous_calls.jsonl");
DecompInterface di = new DecompInterface();
di.openProgram(currentProgram);
SymbolTable st = currentProgram.getSymbolTable();
ReferenceManager rm = currentProgram.getReferenceManager();
FunctionManager fm = currentProgram.getFunctionManager();
Set<String> seen = new HashSet<>();
int emitted = 0;
try (PrintWriter pw = new PrintWriter(new FileWriter(out))) {
for (String sink : SINKS) {
// Mach-O prefixes C symbols with an underscore; PE imports may be __imp_-prefixed.
String[] names = { sink, "_" + sink, "__imp_" + sink };
for (String n : names) {
SymbolIterator it = st.getSymbols(n);
while (it.hasNext() && !monitor.isCancelled()) {
Symbol s = it.next();
for (Reference r : rm.getReferencesTo(s.getAddress())) {
Address from = r.getFromAddress();
Function caller = fm.getFunctionContaining(from);
// A reference from a one-instruction thunk: follow it one level.
if (caller != null && caller.isThunk()) {
for (Reference r2 : rm.getReferencesTo(caller.getEntryPoint())) {
emit(pw, di, fm, seen, sink, r2.getFromAddress());
emitted++;
}
continue;
}
if (emit(pw, di, fm, seen, sink, from)) emitted++;
}
}
}
}
}
println("[NeuroSploit] NsDangerousCalls: " + emitted + " call site(s) -> " + out.getAbsolutePath());
}
private boolean emit(PrintWriter pw, DecompInterface di, FunctionManager fm,
Set<String> seen, String sink, Address site) throws Exception {
Function f = fm.getFunctionContaining(site);
if (f == null) return false;
String key = sink + "@" + f.getEntryPoint();
if (!seen.add(key)) return false;
String code = "";
DecompileResults res = di.decompileFunction(f, 30, monitor);
if (res != null && res.decompileCompleted() && res.getDecompiledFunction() != null) {
code = clip(res.getDecompiledFunction().getC(), 80);
}
pw.println("{\"sink\":\"" + esc(sink) + "\",\"caller\":\"" + esc(f.getName())
+ "\",\"caller_entry\":\"" + f.getEntryPoint() + "\",\"call_site\":\"" + site
+ "\",\"decompiled\":\"" + esc(code) + "\"}");
return true;
}
}