BloodHoundAD / SharpHound2

The Old BloodHound C# Ingestor (Deprecated)
509 stars 113 forks source link

SessionLoop error System.Console.get_KeyAvailable() #66

Open clock-workorange opened 5 years ago

clock-workorange commented 5 years ago

OS: Windows 2008 R2 Enterprise

Build: Public Release SharpHound 2.1 Mar 14,2019, 5:25PM GMT-5

AV: No

Software: CS 3.13 beacon 32 bits

Command line: shell SharpHound.exe -c SessionLoop --MaxLoopTime 2h --LoopDelay 600

[*] Tasked beacon to run: SharpHound.exe -c SessionLoop --MaxLoopTime 2h --LoopDelay 600 [+] host called home, sent: 93 bytes [+] received output: Initializing BloodHound at 11:02 on 02/04/2019

Session Loop mode specified. Looping will end on 02/04/2019 at 13:02 Looping will start after any other collection methods Resolved Collection Methods to SessionLoop Starting Enumeration for testing.local Status: 1318 objects enumerated (+1318 Infinito/s --- Using 60 MB RAM ) Finished enumeration for testing.local in 00:00:00.4436419 0 hosts failed ping. 0 hosts timedout. Starting Session Loop Mode. Status: 472 objects enumerated (+422 8,137931/s --- Using 86 MB RAM Status: 1318 objects enumerated (+1 5,293173/s --- Using 54 MB RAM ) Finished enumeration for testing.local in 00:04:09.8017908 X hosts failed ping. X hosts timedout.

Unhandled Exception: System.InvalidOperationException: Cannot see if a key has been pressed when either application does not have a console or when console input has been redirected from a file. Try Console.In.Peek.

at System.Console.get_KeyAvailable()

at Sharphound2.Enumeration.EnumerationRunner.StartSessionLoopEnumeration()

at Sharphound2.Enumeration.EnumerationRunner.StartEnumeration()

at Sharphound2.Sharphound.Main(String[] args)

Command Line Used: execute-assembly /root/SharpHound.exe -c SessionLoop --MaxLoopTime 2h --LoopDelay 600

.................... .................... Status: 1318 objects enumerated (+1 5,293173/s --- Using 54 MB RAM ) Finished enumeration for testing.local in 00:04:09.8017908 X hosts failed ping. X hosts timedout. [-] Invoke_3 on EntryPoint failed.

I think the error is something with this

https://github.com/BloodHoundAD/SharpHound/blob/master/Sharphound2/Enumeration/EnumerationRunner.cs#L461

or maybe this

https://github.com/BloodHoundAD/SharpHound/blob/master/Sharphound2/Enumeration/EnumerationRunner.cs#L567

hkelley commented 5 years ago

Yes, it looks like Sharphound could either go to .NET 4.5 and use Console.IsInputRedirected or use the Console.WindowHeight + Console.WindowWidth hack shown at this URL.

https://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected

I built against 4.5 and just used this extra condition to quiet the errors. Sharphound.exe now seems to be running under a job scheduler.

if (!Console.IsInputRedirected && Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)

hkelley commented 5 years ago

This also seems to work (and allows you to leave the project as .NET 3.5)

if (0 != (Console.WindowHeight + Console.WindowWidth) && Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)