Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

SessionLoop error System.Console.get_KeyAvailable() #66

Open
clock-workorange opened this issue Apr 2, 2019 · 2 comments
Open

SessionLoop error System.Console.get_KeyAvailable() #66

clock-workorange opened this issue Apr 2, 2019 · 2 comments

Comments

@clock-workorange
Copy link

clock-workorange commented Apr 2, 2019

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
Copy link

hkelley commented Apr 24, 2019

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
Copy link

hkelley commented Jul 2, 2019

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants