rsmusllp / king-phisher

Phishing Campaign Toolkit
BSD 3-Clause "New" or "Revised" License
2.23k stars 538 forks source link

ImportError: No module named 'graphene #363

Closed silkrod closed 5 years ago

silkrod commented 5 years ago

Issue Description

tldr -

import graphene.relay ImportError: No module named 'graphene

Reproduction Steps

  1. Start King Phisher
  2. Do something to trigger the crash

Environment Details

Host OS: Debian 9 x86_64 CLI King Phisher Version: Latest

Error Details / Stack Trace

root@host:/opt/king-phisher# ls
CODE_OF_CONDUCT.md  king_phisher       Pipfile        server_config.yml
data            KingPhisher        Pipfile.lock    tests
docs            KingPhisherServer  README.md    tools
INSTALL.md        LICENSE           readthedocs.yml
root@host:/opt/king-phisher# ./KingPhisherServer config_file
Loading .env environment variables…
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/king-phisher/king_phisher/server/__main__.py", line 50, in <module>
    from king_phisher.server import build
  File "/opt/king-phisher/king_phisher/server/build.py", line 39, in <module>
    from king_phisher.server.server import KingPhisherRequestHandler, KingPhisherServer
  File "/opt/king-phisher/king_phisher/server/server.py", line 55, in <module>
    from king_phisher.server import server_rpc
  File "/opt/king-phisher/king_phisher/server/server_rpc.py", line 48, in <module>
    from king_phisher.server.graphql import schema
  File "/opt/king-phisher/king_phisher/server/graphql/schema.py", line 39, in <module>
    import king_phisher.server.graphql.types as gql_types
  File "/opt/king-phisher/king_phisher/server/graphql/types/__init__.py", line 35, in <module>
    from .database import *
  File "/opt/king-phisher/king_phisher/server/graphql/types/database.py", line 38, in <module>
    from . import misc as gql_misctypes
  File "/opt/king-phisher/king_phisher/server/graphql/types/misc.py", line 42, in <module>
    import graphene.relay
ImportError: No module named 'graphene'
root@host:/opt/king-phisher#
root@host:/opt/king-phisher# pip freeze | grep -e graph -e Django
cryptography==1.7.1
Django==2.2
graphene==2.1.3
graphene-django==2.2.0
graphql-core==2.1
graphql-relay==0.4.5
root@host:/opt/king-phisher#
zeroSteiner commented 5 years ago

Run # ./KingPhisherServer --env-install. This could take a while to run, up to 15 minutes if your internet connection is slow and it won't print any output IIRC. This should have been handled when you ran the installer but if you aborted that or something failed it could have skipped this step.

Your last command showing that graphene is installed isn't valid, King Phisher uses pipenv to install it's requirements within a virtual environment to ensure that the dependencies are predictable. Additionally on most systems, pip is for Python 2.7 and King Phisher is Python 3.4+ only at this point. To check correctly you'd need to run pipenv run pip freeze.

silkrod commented 5 years ago

Ok. No longer having that issue but now I am seeing this:

root@host:/opt/king-phisher# ls -la
total 156
drwxr-xr-x 11 root king-phisher 4096 Apr 10 09:42 .
drwxr-xr-x 3 root root 4096 Apr 9 23:16 ..
-rw-r--r-- 1 root king-phisher 3225 Apr 9 23:16 CODE_OF_CONDUCT.md
drwxr-xr-x 7 root king-phisher 4096 Apr 9 23:16 data
drwxr-xr-x 3 root king-phisher 4096 Apr 9 23:16 docs
-rw-r--r-- 1 root king-phisher 29 Apr 9 23:16 .env
drwxr-xr-x 8 root king-phisher 4096 Apr 9 23:16 .git
drwxr-xr-x 3 root king-phisher 4096 Apr 9 23:16 .github
-rw-r--r-- 1 root king-phisher 788 Apr 9 23:16 .gitignore
drwxr-xr-x 3 root root 4096 Apr 10 09:42 $HOME
-rw-r--r-- 1 root king-phisher 1329 Apr 9 23:16 INSTALL.md
drwxr-xr-x 6 root king-phisher 4096 Apr 9 23:21 king_phisher
-rwxr-xr-x 1 root king-phisher 1889 Apr 9 23:16 KingPhisher
-rwxr-xr-x 1 root king-phisher 1895 Apr 9 23:16 KingPhisherServer
-rw-r--r-- 1 root king-phisher 1497 Apr 9 23:16 LICENSE
-rw-r--r-- 1 root king-phisher 1554 Apr 9 23:16 Pipfile
-rw-r--r-- 1 root root 57987 Apr 10 09:38 Pipfile.lock
-rw-r--r-- 1 root king-phisher 5789 Apr 9 23:16 README.md
-rw-r--r-- 1 root king-phisher 157 Apr 9 23:16 readthedocs.yml
-rw-r--r-- 1 root root 4756 Apr 9 23:40 server_config.yml
drwxr-xr-x 4 root king-phisher 4096 Apr 9 23:16 tests
drwxr-xr-x 4 root king-phisher 4096 Apr 9 23:16 tools
drwxr-xr-x 6 root king-phisher 4096 Apr 9 23:18 .venv
root@host:/opt/king-phisher# ./KingPhisherServer server_config.yml
Loading .env environment variables…
ERROR failed to bind server to address (socket error #98)
ERROR socket error #98 (Address already in use)
Traceback (most recent call last):
File "/opt/king-phisher/king_phisher/server/build.py", line 145, in server_from_config
server = KingPhisherServer(config, plugin_manager, handler_klass, addresses=addresses, ssl_certfile=ssl_certfile, ssl_keyfile=ssl_keyfile)
File "/opt/king-phisher/king_phisher/server/server.py", line 870, in init
super(KingPhisherServer, self).init(handler_klass, *args, **kwargs)
File "/opt/king-phisher/.venv/lib/python3.5/site-packages/advancedhttpserver.py", line 1791, in init
server = server_klass((address[0], address[1]), handler_klass, config=self.__config)
File "/opt/king-phisher/.venv/lib/python3.5/site-packages/advancedhttpserver.py", line 713, in init
super(ServerNonThreaded, self).init(*args, **kwargs)
File "/usr/lib/python3.5/socketserver.py", line 441, in init
self.server_activate()
File "/usr/lib/python3.5/socketserver.py", line 463, in server_activate
self.socket.listen(self.request_queue_size)
OSError: [Errno 98] Address already in use
CRITICAL server failed to build with error: socket error #98 (Address already in use)
root@host:/opt/king-phisher#

I added the servers IP to the server_config.yml earlier. Should I revert it back to 0.0.0.0?

zeroSteiner commented 5 years ago

What's probably more important is the port. It looks like you have something else already running on the port (most likely 80). Do you either a second instance of King Phisher already running or another web server like Apache or Nginx?

silkrod commented 5 years ago

Yes I had apache running but I ran 'service apache2 stop'.

Should I remove it completely? If so, how?

zeroSteiner commented 5 years ago

You don't need to uninstall it, just stop it and probably disable it so it doesn't automatically start the next time you reboot.

silkrod commented 5 years ago

Ok. So I didn't get any error messages but it's not telling me that the daemon is running. Unable to connect to the server from the client box either.

Client error message is reading: "Failed To Connect To The King Phisher RPC Service Can not contact the RPC HTTP service, ensure that the King Phisher Server is currently running on port 80"

root@host:/opt/king-phisher# ./KingPhisherServer server_config.yml
Loading .env environment variables…
ERROR    failed to bind server to address (socket error #98)
ERROR    socket error #98 (Address already in use)
Traceback (most recent call last):
  File "/opt/king-phisher/king_phisher/server/build.py", line 145, in server_from_config
    server = KingPhisherServer(config, plugin_manager, handler_klass, addresses=addresses, ssl_certfile=ssl_certfile, ssl_keyfile=ssl_keyfile)
  File "/opt/king-phisher/king_phisher/server/server.py", line 870, in __init__
    super(KingPhisherServer, self).__init__(handler_klass, *args, **kwargs)
  File "/opt/king-phisher/.venv/lib/python3.5/site-packages/advancedhttpserver.py", line 1791, in __init__
    server = server_klass((address[0], address[1]), handler_klass, config=self.__config)
  File "/opt/king-phisher/.venv/lib/python3.5/site-packages/advancedhttpserver.py", line 713, in __init__
    super(ServerNonThreaded, self).__init__(*args, **kwargs)
  File "/usr/lib/python3.5/socketserver.py", line 441, in __init__
    self.server_activate()
  File "/usr/lib/python3.5/socketserver.py", line 463, in server_activate
    self.socket.listen(self.request_queue_size)
OSError: [Errno 98] Address already in use
CRITICAL server failed to build with error: socket error #98 (Address already in use)
root@host:/opt/king-phisher# service apache2 stop
root@host:/opt/king-phisher# ./KingPhisherServer server_config.yml
Loading .env environment variables…
root@host:/opt/king-phisher# 
zeroSteiner commented 5 years ago

Well is the server running on port 80?

silkrod commented 5 years ago

Sorry if this is wrong.. but is this what you were looking for?

root@host:/opt/king-phisher# netstat --listen --tcp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 104.243.xx.xxx:http     0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 localhost:postgresql    0.0.0.0:*               LISTEN     
tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN     
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN     
tcp6       0      0 localhost:postgresql    [::]:*                  LISTEN     
root@host:/opt/king-phisher# netstat --listen --tcp -n
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 104.243.xx.xxx:80       0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:5432                :::*                    LISTEN     
root@host:/opt/king-phisher# 
zeroSteiner commented 5 years ago

Oh yeah, that's probably your issue. If you changed 0.0.0.0 to your external IP address then the client won't be able to connect to the lookback interface when it SSHes in. I'd suggest changing that back to it's default value. If you can't bind to all interfaces, it'd be more complicated to setup. The easiest thing to do would be to set the interface back.

silkrod commented 5 years ago

Awesome, I am able to connect to the server now from the client.

My last question/issue (I promise) is that I don't know what to enter in the "Web Server URL" field. I have a domain pointed to my server but I don't think this program recognizes that. I haven't created any email accounts or installed postfix etc. Could you just give me a quick list of what I would need to do? There was nothing that installed automatically to the web root "/var/www/" so I'm not sure what it's looking for.

zeroSteiner commented 5 years ago

Okay, so we have a wiki section on configuring the web root which should help you out. TLDR, it's your webroot unless you enabled vhosts, in which you need to make subdirectories which are your webroot.

The "Web Server URL" field is just the URL to the landing page in your webroot. Take a look at the public templates repository under Website Templates to find some content to put there. Keep in mind, if you try to navigate there yourself without having phished yourself first you'll most likely see the 404 page.

silkrod commented 5 years ago

What if I already have a template setup on another server/domain? What would I input in to the Web Server URL field?

Would I just simply add the /kp.js to the index?

zeroSteiner commented 5 years ago

Well for the King Phisher server to collect the data the template needs to be hosted by it. If you don't care and just want to know if a user visited the link you could create a simple landing page that just redirected them to your other server.

silkrod commented 5 years ago

Checking the target URL... success, done. Skipped checking the SPF policy because the SMTP server address could not be detected. Sending messages started at: Wednesday April 10, 2019 12:19:47 Message mode is: Email Connecting to SMTP server... failed

silkrod commented 5 years ago

Should I install postfix and create an email on the kingphisher server and then input that email in to the Source Email (SMTP) field?

zeroSteiner commented 5 years ago

Yes