Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output of a port scanner #15

Open
0xPawn opened this issue Sep 28, 2017 · 2 comments
Open

Output of a port scanner #15

0xPawn opened this issue Sep 28, 2017 · 2 comments

Comments

@0xPawn
Copy link

0xPawn commented Sep 28, 2017

Hi,
Is it possible to get the output of a port scanner?

My code is:

client = MsfRpcClient(password = "RpcPass1010" , port = '61020')

scanner = client.modules.use('auxiliary', 'scanner/portscan/tcp')
scanner['PORTS'] = '80, 8080'
scanner['RHOSTS'] = '192.168.2.8'
scanner['THREADS'] = 10
scanner['TIMEOUT'] = 1
scanner.execute()

Do I need to change anything or add something to get the output of this?

Thank you

@yg-ht
Copy link

yg-ht commented Jan 2, 2018

My understanding is that your code will just execute the instruction, however, actually reading back the result will need further code. This is because some modules take a while to execute, which means MSFRPC is a-synchronous, allowing you to perform other actions whilst waiting for the results to come back.

I was thinking maybe checking the outstanding jobs, and then when there are no jobs left, to check the output of it, but unfortunately the job no longer exists once it is complete and no session was created (because it is just an auxiliary module) so there is nothing here to check either.

I want to work this out as well - did you get to the bottom of it?

@yg-ht
Copy link

yg-ht commented Jan 2, 2018

I wasn't thinking clearly last night. I also took inspiration from:

http://www.primalsecurity.net/python-for-metasploit-automation/

Which is actually regarding a different Python / MSFRPC / MSGRPC library. I ended up producing the following function:

def executeMSFcommand(self, msfConsole, msfCommand, printOutput=False):
    msfConsole.write(msfCommand)
    msfReady = False
    while (not msfReady):
        msfResult = msfConsole.read()
        if (not msfResult['busy']):
            msfReady = True
    if (printOutput):
        # The below filter / lambda functions are required to filter out unicode chars, as the "color false" doesn't apply properly
        print(filter(lambda x: x in self.string.printable, msfResult['data']))
        #print(filter(lambda x: x in self.string.printable, msfResult['prompt']))
    else:
        return msfResult

The init function of my class includes this to get started too:

    msfClient = self.msfrpc.MsfRpcClient(self.settings.msfrpcPass, username=self.settings.msfrpcUser)
    msfConsole = self.msfrpc.MsfConsole(msfClient)

Probably not the neatest code in the world, but it works. This is the rest of my repo that uses it:

https://github.com/yg-ht/FIR/blob/198f038b4000719e08ab18ef7946a831d717a63a/functions.py

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

No branches or pull requests

2 participants