SECFORCE / sparta

Network Infrastructure Penetration Testing Tool
GNU General Public License v3.0
1.61k stars 445 forks source link

SQL error, how to fix this problem ? #63

Closed montano684 closed 7 years ago

montano684 commented 7 years ago

[+] Creating temporary files.. [+] Wordlist was created/opened: /tmp/sparta-o7pHtj-tool-output/sparta-usernames.txt [+] Wordlist was created/opened: /tmp/sparta-o7pHtj-tool-output/sparta-passwords.txt [-] Could not create database. Please try again. [+] Loading settings file.. Traceback (most recent call last): File "sparta.py", line 89, in controller = Controller(view, logic) # Controller prep (communication between model and view) File "/usr/share/sparta/controller/controller.py", line 34, in init self.start() # initialisations (globals, etc) File "/usr/share/sparta/controller/controller.py", line 46, in start self.view.start(title) File "/usr/share/sparta/ui/view.py", line 89, in start self.updateInterface() File "/usr/share/sparta/ui/view.py", line 1133, in updateInterface self.updateServiceNamesTableView() File "/usr/share/sparta/ui/view.py", line 870, in updateServiceNamesTableView self.ServiceNamesTableModel = ServiceNamesTableModel(self.controller.getServiceNamesFromDB(self.filters), headers) File "/usr/share/sparta/controller/controller.py", line 404, in getServiceNamesFromDB return self.logic.getServiceNamesFromDB(filters) File "/usr/share/sparta/app/logic.py", line 230, in getServiceNamesFromDB return metadata.bind.execute(tmp_query).fetchall() File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2297, in execute return connection.execute(statement, *multiparams, **params) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1405, in execute params) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1582, in _execute_text statement, parameters File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1646, in _execute_context context) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1639, in _execute_context context) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 330, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (OperationalError) no such table: db_tables_nmap_service "SELECT DISTINCT service.name FROM db_tables_nmap_service as service INNER JOIN db_tables_nmap_port as ports INNER JOIN db_tables_nmap_host AS hosts ON hosts.id = ports.host_id AND service.id=ports.service_id WHERE 1=1 AND hosts.status!='down' AND ports.state!='closed' AND ports.state!='filtered' AND ports.state!='open|filtered' ORDER BY service.name ASC" ()

st3r30byt3 commented 7 years ago

Hi! From the trace you shared, DB creation is failing when you launch SPARTA. This seems to indicate that either you don't have the right permissions or that you may be missing some dependency,

Could you provide more details about your environment (eg: version of Kali, version of Python, if you installed all dependencies, what user are you)?

montano684 commented 7 years ago

Linux maestr0 4.8.0-kali2-amd64 #1 SMP Debian 4.8.11-1kali1 (2016-12-08) x86_64 GNU/Linux

/usr/bin/python2.7: Python 2.7.13rc1

Yeap all deps are installed

user - root

st3r30byt3 commented 7 years ago

Hi. We are looking into this. Other users have also reported this issue.

Was this when running the version included in Kali or the one downloaded from Git?

KaliSentinelX commented 7 years ago

For me it has been both versions

st3r30byt3 commented 7 years ago

Thanks for the info.

Just downloaded the latest Kali iso from here: http://cdimage.kali.org/kali-2016.2/kali-linux-2016.2-amd64.iso

Prior to updating anything and without installing any dependency, simply typing 'sparta' in a terminal worked. Cloning from this repo and running it also worked out of the box.

I am currently updating this recently downloaded Kali to see if that's what causes the issue.

In our dev environment which is a fully updated rolling Kali downloaded a few months ago it runs without problems too (Linux kali 4.8.0-kali2-amd64 #1 SMP Debian 4.8.15-1kali1 (2016-12-23) x86_64 GNU/Linux).

It seems that my kernel version is more recent than yours but that's the only difference that jumps to mind and it shouldn't be a problem.

I am not entirely sure where the issue is coming from. Is there any other detail you could provide? Have you tried the very latest Kali and if so, may I ask which iso?

KaliSentinelX commented 7 years ago

I did fresh kali install from the kali 64bit iso without any updates and it works just fine. If you update to the latest kali then it throws out the error thats already documented. I tried just now with the git version and it gets the same error as well as the kali. I tried this on both of my kali machines which are both using Linux kali 4.8.0-kali2-amd64 #1 SMP Debian 4.8.15-1kali1 (2016-12-23) x86_64 GNU/Linux. I check python 2.7 and all dependencies are up to date. If there is anything else I can provide for you please let me know and thank you for taking your time to look into this.

st3r30byt3 commented 7 years ago

I am very sorry but cannot reproduce this bug.

On the same Kali previously downloaded (rolling) these actions were performed in this order:

Is it possible that you guys installed/uninstalled a package which somehow changed the dependencies?

After all of the steps above I have these package versions, do you? python-elixir 0.7.1-4 python-sqlalchemy 1.0.15+ds1-1 python-qt4 4.11.4+dfsg-2kali1 xsltproc 1.1.29-2 python 2.7.13

From Kali's bug tracker, it seems that one of their updates had broken SPARTA but they fixed it: https://bugs.kali.org/changelog_page.php

Maybe try a dist-upgrade followed by updating again?

Let me know if this helps.

KaliSentinelX commented 7 years ago

I followed your post exactly and verified the versions of the packages which are the same that you pointed out. I updated one machine to kali 4.9.0 with 4.9.6 and the other I left at 4.8.0 with 4.8.15. I still get the same error. I tried the git sparta and the one that comes with kali and still no luck. Maybe if I reboot enough times and yell at it, sparta will work lol. Thank you for looking into it you guys are awesome keep up the good work!

KaliSentinelX commented 7 years ago

Setting up python-sqlalchemy (1.0.15+ds1-1) ... Setting up python-elixir (0.7.1-4) ... Setting up python-sqlalchemy-ext (1.0.15+ds1-1) ... Setting up xsltproc (1.1.29-2) python is 2.7.13 Setting up sparta (1.0.1+git20150729-0kali2) ...

I have tried installing and reinstalling every dependency,sparta, and the sparta from git and still no luck. This is now on 4.9.0-kali1-amd64 #1 SMP Debian 4.9.6-3kali2 (2017-01-30) x86_64 GNU/Linux for both of my machines. I have no idea what is going on seeing as that we have everything the same.

st3r30byt3 commented 7 years ago

You can try yelling a bit more at it, sometimes it works but how familiar are you with python? :)

The best way to troubleshoot this would be to edit the file sparta/db/database.py and change the init function to not do a try/except so that it displays the actual error.

To do this, it's pretty easy: you should comment out lines 24, 31 and 32. You will probably need to fix indentation after that.

After you save, run SPARTA again and see what error you get.

Let me know if this helps.

KaliSentinelX commented 7 years ago

I opened /Downloads/sparta-master(1)/sparta-master/db/database.py in Wing.IDE 6.0 and comment out lines 24 ,31 ,32. This is the output that I got I also tried it in /Sparta/db/database.py Traceback (most recent call last): File "./sparta.py", line 89, in controller = Controller(view, logic) # Controller prep (communication between model and view) File "/root/Downloads/sparta-master(1)/sparta-master/controller/controller.py", line 34, in init self.start() # initialisations (globals, etc) File "/root/Downloads/sparta-master(1)/sparta-master/controller/controller.py", line 44, in start self.nmapImporter.setDB(self.logic.db) # tell nmap importer which db to use AttributeError: Logic instance has no attribute 'db'

st3r30byt3 commented 7 years ago

Hey. Could you send the full stack trace? That's not making much sense :)

In the very first post, the init function was clearly throwing an exception but in the last stack trace you posted it seems that the program is not crashing in the same place.

It's very difficult to troubleshoot remotely :(

KaliSentinelX commented 7 years ago

I hope this is what you mean if not let me know. I made a side note at the bottom of the post [+] Creating temporary files.. [+] Wordlist was created/opened: /tmp/sparta-Nm093p-tool-output/sparta-usernames.txt [+] Wordlist was created/opened: /tmp/sparta-Nm093p-tool-output/sparta-passwords.txt [-] Something went wrong creating the temporary files.. [-] Unexpected error: <type 'exceptions.TypeError'> [+] Loading settings file.. Traceback (most recent call last): File "./sparta.py", line 89, in controller = Controller(view, logic) # Controller prep (communication between model and view) File "/root/Downloads/sparta-master(1)/sparta-master/controller/controller.py", line 34, in init self.start() # initialisations (globals, etc) File "/root/Downloads/sparta-master(1)/sparta-master/controller/controller.py", line 44, in start self.nmapImporter.setDB(self.logic.db) # tell nmap importer which db to use AttributeError: Logic instance has no attribute 'db'

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// I was messing around in wing ide with the database.py and hit debug which kicked back this File "/usr/lib/python2.7/dist-packages/elixir/entity.py", line 455, in setup_mapper elif isinstance(self.session, scoped_session):

TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

I'll be honest am not a developer or that experienced in python as am still in the beginning stages but I figured post this just in case it is relevant. In case that is not....

st3r30byt3 commented 7 years ago

Yes, that second part is more helpful and makes more sense. Python Elixir is what we are using to handle database stuff and that's what was breaking in the original stack trace that was posted.

Unfortunately, it's hard to tell why your version of Elixir is throwing an error given that it's the same as everyone else's :)

I am sorry, but am not sure we can do much more about it other than what we have already done. It seems to work on a newly downloaded, installed, updated and upgraded Kali.

KaliSentinelX commented 7 years ago

No worries you have been awesome and I appriciate the hard work. Eventually I will have it working am sure I must have messed something up sometime ago or whatever.

On Feb 2, 2017 7:37 AM, "Antonio Quina" notifications@github.com wrote:

Yes, that second part is more helpful and makes more sense. Python Elixir is what we are using to handle database stuff and that's what was breaking in the original stack trace that was posted.

Unfortunately, it's hard to tell why your version of Elixir is throwing an error given that it's the same as everyone else's :)

I am sorry, but am not sure we can do much more about it other than what we have already done. It seems to work on a newly downloaded, installed, updated and upgraded Kali.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SECFORCE/sparta/issues/63#issuecomment-276958818, or mute the thread https://github.com/notifications/unsubscribe-auth/ATyDvRL2jYPDvKoClkkypM9tOBLVLzFkks5rYdwZgaJpZM4LKaN6 .

KaliSentinelX commented 7 years ago

I finally narrowed down what the issue was. I use Pentesters Framework to keep a majority of my toolsdist-infop to date. If you installed snoopy-ng via PTF its going to download SQLAchemy.0.7 if you analyze the packages that are being downloaded. All I did was to go to usr/local/lib/python2.7/dist-packages in there find SQLAlchemy.0.7.4.dist-info and sqlalchemy , delete this two folders. Now sparta works just fine. I did do a reinstall of sparta in-case I was missing any dependencies

st3r30byt3 commented 7 years ago

I'm glad you found the issue. Closing this for now.