question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

King Phisher systemd service start failure

See original GitHub issue

Issue Description

Upon installing king phisher on a fresh Debian 9 server, I found that the systemd start method for the king-phisher service fails due to a very cryptic error related to ASCII encoding. Even after following the instructions in the error by exporting the appropriate environment variables, the error remains. The issue appears to be related to the pipenv package, perhaps because UTF-8 encoding is not specified in one of the file headers, or possible upstream issues with the latest pipenv package, but I’m just speculating.

Note that running ./KingPhisherServer server_config.yml from the local directory runs just fine without any issues.

Reproduction Steps

  1. Load a fresh Debian Stretch installation (I’m using a digital ocean image, for context)
  2. Run the tools/install.sh script
  3. Behold the stacktrace

Environment Details

Host OS: Debian Stretch (9) Linux 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64 KingPhisher Version: 1.13.2 (rev: 3d6a1b59730b) (latest master)

Error Details / Stack Trace

Here is the systemd startup where the error occurs.

05:09:30 root@1551299135 king-phisher ±|master|→ systemctl start king-phisher
Job for king-phisher.service failed because the control process exited with error code.
See "systemctl status king-phisher.service" and "journalctl -xe" for details.
05:09:33 root@1551299135 king-phisher ±|master|→ journalctl -xe
Jul 05 16:45:01 1551299135 CRON[19486]: pam_unix(cron:session): session opened for user root by (uid=0)
Jul 05 16:45:01 1551299135 CRON[19487]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jul 05 16:45:01 1551299135 CRON[19486]: pam_unix(cron:session): session closed for user root
Jul 05 16:50:50 1551299135 sshd[20560]: Invalid user address from 110.45.145.178 port 52600
Jul 05 16:50:50 1551299135 sshd[20560]: input_userauth_request: invalid user address [preauth]
Jul 05 16:50:50 1551299135 sshd[20560]: Received disconnect from 110.45.145.178 port 52600:11: Normal Shutdown, Thank you for playing [preauth]
Jul 05 16:50:50 1551299135 sshd[20560]: Disconnected from 110.45.145.178 port 52600 [preauth]
Jul 05 16:54:37 1551299135 sshd[21259]: Invalid user pul from 51.77.221.191 port 56340
Jul 05 16:54:37 1551299135 sshd[21259]: input_userauth_request: invalid user pul [preauth]
Jul 05 16:54:37 1551299135 sshd[21259]: Received disconnect from 51.77.221.191 port 56340:11: Bye Bye [preauth]
Jul 05 16:54:37 1551299135 sshd[21259]: Disconnected from 51.77.221.191 port 56340 [preauth]
Jul 05 16:55:01 1551299135 CRON[21341]: pam_unix(cron:session): session opened for user root by (uid=0)
Jul 05 16:55:01 1551299135 CRON[21342]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jul 05 16:55:01 1551299135 CRON[21341]: pam_unix(cron:session): session closed for user root
Jul 05 17:04:54 1551299135 su[23245]: Successful su for postgres by root
Jul 05 17:04:54 1551299135 su[23245]: + /dev/pts/5 root:postgres
Jul 05 17:04:54 1551299135 su[23245]: pam_unix(su:session): session opened for user postgres by truedemon(uid=0)
Jul 05 17:04:54 1551299135 su[23245]: pam_systemd(su:session): Cannot create session: Already running in a session
Jul 05 17:05:01 1551299135 CRON[23283]: pam_unix(cron:session): session opened for user root by (uid=0)
Jul 05 17:05:01 1551299135 CRON[23284]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jul 05 17:05:01 1551299135 CRON[23283]: pam_unix(cron:session): session closed for user root
Jul 05 17:09:18 1551299135 su[23245]: pam_unix(su:session): session closed for user postgres
Jul 05 17:09:33 1551299135 systemd[1]: Starting King Phisher Server...
-- Subject: Unit king-phisher.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit king-phisher.service has begun starting up.
Jul 05 17:09:33 1551299135 python3[24225]: Traceback (most recent call last):
Jul 05 17:09:33 1551299135 python3[24225]:   File "/usr/local/bin/pipenv", line 10, in <module>
Jul 05 17:09:33 1551299135 python3[24225]:     sys.exit(cli())
Jul 05 17:09:33 1551299135 python3[24225]:   File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 764, in __call__
Jul 05 17:09:33 1551299135 python3[24225]:     return self.main(*args, **kwargs)
Jul 05 17:09:33 1551299135 python3[24225]:   File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/core.py", line 696, in main
Jul 05 17:09:33 1551299135 python3[24225]:     _verify_python3_env()
Jul 05 17:09:33 1551299135 python3[24225]:   File "/usr/local/lib/python3.5/dist-packages/pipenv/vendor/click/_unicodefun.py", line 124, in _verify_python3_env
Jul 05 17:09:33 1551299135 python3[24225]:     ' mitigation steps.' + extra
Jul 05 17:09:33 1551299135 python3[24225]: RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/en/7.x/python3/ for mitiga
Jul 05 17:09:33 1551299135 python3[24225]: This system supports the C.UTF-8 locale which is recommended.
Jul 05 17:09:33 1551299135 python3[24225]: You might be able to resolve your issue by exporting the
Jul 05 17:09:33 1551299135 python3[24225]: following environment variables:
Jul 05 17:09:33 1551299135 python3[24225]:     export LC_ALL=C.UTF-8
Jul 05 17:09:33 1551299135 python3[24225]:     export LANG=C.UTF-8
Jul 05 17:09:33 1551299135 systemd[1]: king-phisher.service: Control process exited, code=exited status=1
Jul 05 17:09:33 1551299135 systemd[1]: Failed to start King Phisher Server.
-- Subject: Unit king-phisher.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit king-phisher.service has failed.
-- 
-- The result is failed.
Jul 05 17:09:33 1551299135 systemd[1]: king-phisher.service: Unit entered failed state.
Jul 05 17:09:33 1551299135 systemd[1]: king-phisher.service: Failed with result 'exit-code'.

Here is the contents of /lib/systemd/system/king-phisher.service

# KingPhisherServer systemd config file
# This file goes in /lib/systemd/system/

[Unit]
Description=King Phisher Server
After=syslog.target network.target auditd.service

[Service]
Type=forking
PIDFile=/var/run/king-phisher.pid
WorkingDirectory=/usr/share/king-phisher
# Installed Together In /usr/share/king-phisher
ExecStart=/usr/bin/python3 /usr/share/king-phisher/KingPhisherServer /usr/share/king-phisher/server_config.yml
ExecStop=/bin/kill -INT $MAINPID

[Install]
WantedBy=multi-user.target

Here is the output from ./KingPhisherServer -L DEBUG server_config.yml

05:27:12 root@1551299135 king-phisher ±|master|→ ./KingPhisherServer -L DEBUG server_config.yml 
DEBUG    target directory: /usr/share/king-phisher
INFO     checking for the pipenv environment
DEBUG    pipenv path: '/usr/local/bin/pipenv'
DEBUG    pipenv Pipfile: /usr/share/king-phisher/Pipfile
Loading .env environment variables…
DEBUG    king phisher version: 1.13.2 (rev: 3d6a1b59730b) python version: 3.5.3
DEBUG    plugin dependency path: /root/.local/lib/king-phisher/python3.5/site-packages
INFO     listening on 0.0.0.0:80
INFO     serving files has been enabled
INFO     initializing database connection with driver postgresql
DEBUG    postgresql-setup was not found
DEBUG    postgresql service is already running via systemctl
DEBUG    current database schema version: 9 (latest)
DEBUG    connected to postgresql database: king_phisher
INFO     restored 0 valid sessions and skipped 0 expired sessions from the database
DEBUG    use pam service 'sshd' for authentication
DEBUG    forked an authenticating process with pid: 31628
INFO     the job manager has been started
05:27:17 root@1551299135 king-phisher ±|master|→ INFO     adding new job with id: e31d12ce-e9eb-41bf-9a99-30bf95da0d1f and callback function: _maintenance
INFO     adding new job with id: 4aa07f6e-7b1d-4080-9d5d-f49954f923ab and callback function: ping_all
DEBUG    web socket manager worker running in tid: 0x7fc9177b8700
DEBUG    initialized the table api dataset (schema version: 8)
INFO     including 4 custom http headers
INFO     server running in process: 31591 main tid: 0x7fc9227b1700
INFO     dropped privileges to the nobody account
DEBUG    executing job with id: 4aa07f6e-7b1d-4080-9d5d-f49954f923ab and callback function: ping_all
DEBUG    executing job with id: e31d12ce-e9eb-41bf-9a99-30bf95da0d1f and callback function: _maintenance
DEBUG    running periodic maintenance tasks
DEBUG    executing job with id: 4aa07f6e-7b1d-4080-9d5d-f49954f923ab and callback function: ping_all
DEBUG    executing job with id: 4aa07f6e-7b1d-4080-9d5d-f49954f923ab and callback function: ping_all

Totally baffled why this fails to run under systemd, but manually executing & forking the server from the local directory works just fine. It is loading the exact same environment either way. Manually running from within pipenv yields the same results as running locally outside pipenv

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zeroSteinercommented, Jul 5, 2019

Yeah it probably has something to do with the service configuration file. It might need the locale to be specified.

Thanks for reporting this though, someone will look into on Monday.

0reactions
stale[bot]commented, Jul 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

King Phisher systemd service start failure · Issue #382 - GitHub
Upon installing king phisher on a fresh Debian 9 server, I found that the systemd start method for the king-phisher service fails due...
Read more >
https://raw.githubusercontent.com/securestate/king...
Project Home Page: https://github.com/securestate/king-phisher/ # Authors: ... if ! service postgresql start &> /dev/null; then echo "ERROR: Could not start ...
Read more >
Linux useradd command | userdel |/etc/passwd - IPCisco
In this linux lesson, we will use linux useradd command and learn how to add a new user to linux, how to delete...
Read more >
Untitled
Star city silverbacks, Como descargar pp25, Cejas pintadas horribles, Sunburn goa 2012 ... Sun king the beatles subtitulada, Hair loss stem cell treatment....
Read more >
Kali Linux TroubleShooting
Failed to restart systemd-resolved.service: Unit systemd-resolved.service not ... Kali Linux CRASHES during startup. ... King Phisher refuses to launch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found