nettitude / PoshC2

A proxy aware C2 framework used to aid red teamers with post-exploitation and lateral movement.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Help Required] Getting Certificate Error while starting Posh Server

manoj30 opened this issue · comments

I have installed latest PoshC2 on Kali Linux using below command.

curl -sSL https://raw.githubusercontent.com/nettitude/PoshC2/master/Install.sh | bash

I am getting below certificate error while running posh-server.
Traceback (most recent call last):
File "start.py", line 8, in <module>
run()
File "/opt/PoshC2/poshc2/__init__.py", line 13, in run
server.start()
File "/opt/PoshC2/poshc2/server/__init__.py", line 10, in start
main(args)
File "/opt/PoshC2/poshc2/server/C2Server.py", line 754, in main
raise ValueError("Cannot find the certificate files")
ValueError: Cannot find the certificate files

Execution Environment

Kali Linux.

Could anyone please help me out here.

Code is trying to find out certificate and key files in /opt/PoshC2_Project.
Can we bypass this certificate check.

Hi,

Can you remove the project folder and start the server again.

e.g.

rm -rf /opt/PoshC2_Project.
posh-server or posh-service

Thanks for reply.
After deleting above folder, I've received below error.

Initializing new project folder and sqlite database

Creating Rewrite Rules in: /opt/PoshC2_Project/rewrite-rules.txt

Raw Payload written to: /opt/PoshC2_Project/payloads/payload.txt Batch Payload written to: /opt/PoshC2_Project/payloads/payload.bat C# Dropper Payload written to: /opt/PoshC2_Project/payloads/dropper.cs /bin/sh: 1: mono-csc: not found Traceback (most recent call last): File "start.py", line 8, in <module> run() File "/opt/PoshC2/poshc2/__init__.py", line 13, in run server.start() File "/opt/PoshC2/poshc2/server/__init__.py", line 10, in start main(args) File "/opt/PoshC2/poshc2/server/C2Server.py", line 724, in main newdb("sqlite") File "/opt/PoshC2/poshc2/server/C2Server.py", line 627, in newdb newPayload.CreateDlls() File "/opt/PoshC2/poshc2/server/Payloads.py", line 222, in CreateDlls subprocess.check_output(compile, shell=True) File "/usr/lib/python3.8/subprocess.py", line 411, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.8/subprocess.py", line 512, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command 'mono-csc /opt/PoshC2_Project/payloads/dropper.cs -out:/opt/PoshC2_Project/payloads/dropper_cs.dll -target:library -sdk:4 -warn:1' returned non-zero exit status 127.

I had received same error while running posh-server first time. (I re-ran posh-server and I got certificate issue)
I tried to google it. It seems csharp compiler package is not installed. I tried to find out the solution. But mono packages are not available.

It looks like some dependencies didn't successfully install. Are you running this in Kali or via Docker?

It might be worth running the install and checking any errors for packages.

I am using Kali VM.
I have tried to run Install.sh script from /opt/PoshC2 directory as a root.
I got below error but at the same time script went ahead and said
[+]Setup complete.
Output:
✔ Successfully created virtual environment!
Virtualenv location: /root/.local/share/virtualenvs/PoshC2-KGSTtxLR
✔ Success!
|
|
|
ERROR: Command errored out with exit status 1:
command: /root/.local/share/virtualenvs/PoshC2-KGSTtxLR/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-536cbixv/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-536cbixv/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-o26le6kr
|
|
|
ERROR: Failed building wheel for psycopg2

Is it required to install psycopg2. (As setup said complete). I thought certificate issue is unrelated to this error.
So I asked about it.

psycopg2 is only required if you're using a Postgres database instead of the SQLite one, but if pip fails for one thing it bombs out and fails to install anything else after that which probably includes the openssl stuff required to create the certs.

Not sure why a pip install is failing on your host, you'd have to provide more info for that but for now if you're not using Postgres you can remove psycopg2 from requirements.txt and try running the install script again, see if we can just bypass the issue altogether...

Hi,
As Ben had pointed out that there could be dependencies issue, I downloaded and imported OVA file available on kali.org.
Now I am able to start server successsfully.

Thanks a lot.

commented

psycopg2 is only required if you're using a Postgres database instead of the SQLite one, but if pip fails for one thing it bombs out and fails to install anything else after that which probably includes the openssl stuff required to create the certs.

Not sure why a pip install is failing on your host, you'd have to provide more info for that but for now if you're not using Postgres you can remove psycopg2 from requirements.txt and try running the install script again, see if we can just bypass the issue altogether...

FWIW this is the psycopg2 error:

$ sudo pipenv install
Installing dependencies from Pipfile.lock (8bb229)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00
An error occurred while installing psycopg2==2.8.5 --hash=sha256:27c633f2d5db0fc27b51f1b08f410715b59fa3802987aec91aeb8f562724e95c --hash=sha256:2327bf42c1744a434ed8ed0bbaa9168cac7ee5a22a9001f6fc85c33b8a4a14b7 --hash=sha256:132efc7ee46a763e68a815f4d26223d9c679953cd190f1f218187cb60decf535 --hash=sha256:6b306dae53ec7f4f67a10942cf8ac85de930ea90e9903e2df4001f69b7833f7e --hash=sha256:2df2bf1b87305bd95eb3ac666ee1f00a9c83d10927b8144e8e39644218f4cf81 --hash=sha256:acf56d564e443e3dea152efe972b1434058244298a94348fc518d6dd6a9fb0bb --hash=sha256:6a471d4d2a6f14c97a882e8d3124869bc623f3df6177eefe02994ea41fd45b52 --hash=sha256:a0984ff49e176062fcdc8a5a2a670c9bb1704a2f69548bce8f8a7bad41c661bf --hash=sha256:440a3ea2c955e89321a138eb7582aa1d22fe286c7d65e26a2c5411af0a88ae72 --hash=sha256:2c0afb40cfb4d53487ee2ebe128649028c9a78d2476d14a67781e45dc287f080 --hash=sha256:ac5b23d0199c012ad91ed1bbb971b7666da651c6371529b1be8cbe2a7bf3c3a9 --hash=sha256:d3b29d717d39d3580efd760a9a46a7418408acebbb784717c90d708c9ed5f055 --hash=sha256:f7d46240f7a1ae1dd95aab38bd74f7428d46531f69219954266d669da60c0818! Will try again.
Installing initially failed dependencies…
[InstallError]:   File "/usr/local/lib/python3.8/dist-packages/pipenv/cli/command.py", line 232, in install
[InstallError]:       retcode = do_install(
[InstallError]:   File "/usr/local/lib/python3.8/dist-packages/pipenv/core.py", line 2051, in do_install
[InstallError]:       do_init(
[InstallError]:   File "/usr/local/lib/python3.8/dist-packages/pipenv/core.py", line 1306, in do_init
[InstallError]:       do_install_dependencies(
[InstallError]:   File "/usr/local/lib/python3.8/dist-packages/pipenv/core.py", line 900, in do_install_dependencies
[InstallError]:       batch_install(
[InstallError]:   File "/usr/local/lib/python3.8/dist-packages/pipenv/core.py", line 796, in batch_install
[InstallError]:       _cleanup_procs(procs, failed_deps_queue, retry=retry)
[InstallError]:   File "/usr/local/lib/python3.8/dist-packages/pipenv/core.py", line 703, in _cleanup_procs
[InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: Collecting psycopg2==2.8.5
[pipenv.exceptions.InstallError]:   Using cached psycopg2-2.8.5.tar.gz (380 kB)
[pipenv.exceptions.InstallError]: Building wheels for collected packages: psycopg2
[pipenv.exceptions.InstallError]:   Building wheel for psycopg2 (setup.py): started
[pipenv.exceptions.InstallError]:   Building wheel for psycopg2 (setup.py): finished with status 'error'
[pipenv.exceptions.InstallError]:   ERROR: Command errored out with exit status 1:
[pipenv.exceptions.InstallError]:    command: /root/.local/share/virtualenvs/PoshC2-KGSTtxLR/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-s5bycdd_/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-s5bycdd_/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-spq9kjh9
[pipenv.exceptions.InstallError]:        cwd: /tmp/pip-install-s5bycdd_/psycopg2/
[pipenv.exceptions.InstallError]:   Complete output (42 lines):
[pipenv.exceptions.InstallError]:   running bdist_wheel
[pipenv.exceptions.InstallError]:   running build
[pipenv.exceptions.InstallError]:   running build_py
[pipenv.exceptions.InstallError]:   creating build
[pipenv.exceptions.InstallError]:   creating build/lib.linux-x86_64-3.8
[pipenv.exceptions.InstallError]:   creating build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/compat.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:   warning: build_py: byte-compiling is disabled, skipping.
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   running build_ext
[pipenv.exceptions.InstallError]:   building 'psycopg2._psycopg' extension
[pipenv.exceptions.InstallError]:   creating build/temp.linux-x86_64-3.8
[pipenv.exceptions.InstallError]:   creating build/temp.linux-x86_64-3.8/psycopg
[pipenv.exceptions.InstallError]:   x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.8.5 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120001 -DHAVE_LO64=1 -I/root/.local/share/virtualenvs/PoshC2-KGSTtxLR/include -I/usr/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statement
[pipenv.exceptions.InstallError]:   In file included from psycopg/psycopgmodule.c:28:
[pipenv.exceptions.InstallError]:   ./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
[pipenv.exceptions.InstallError]:      36 | #include <libpq-fe.h>
[pipenv.exceptions.InstallError]:         |          ^~~~~~~~~~~~
[pipenv.exceptions.InstallError]:   compilation terminated.
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   It appears you are missing some prerequisite to build the package from source.
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   You may install a binary package by installing 'psycopg2-binary' from PyPI.
[pipenv.exceptions.InstallError]:   If you want to install psycopg2 from source, please install the packages
[pipenv.exceptions.InstallError]:   required for the build and try again.
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   For further information please check the 'doc/src/install.rst' file (also at
[pipenv.exceptions.InstallError]:   <https://www.psycopg.org/docs/install.html>).
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
[pipenv.exceptions.InstallError]:   ----------------------------------------
[pipenv.exceptions.InstallError]:   ERROR: Failed building wheel for psycopg2
[pipenv.exceptions.InstallError]:   Running setup.py clean for psycopg2
[pipenv.exceptions.InstallError]: Failed to build psycopg2
[pipenv.exceptions.InstallError]: DEPRECATION: Could not build wheels for psycopg2 which do not use PEP 517. pip will fall back to legacy 'setup.py install' for these. pip 21.0 will remove support for this functionality. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
[pipenv.exceptions.InstallError]: Installing collected packages: psycopg2
[pipenv.exceptions.InstallError]:     Running setup.py install for psycopg2: started
[pipenv.exceptions.InstallError]:     Running setup.py install for psycopg2: finished with status 'error'
[pipenv.exceptions.InstallError]:     ERROR: Command errored out with exit status 1:
[pipenv.exceptions.InstallError]:      command: /root/.local/share/virtualenvs/PoshC2-KGSTtxLR/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-s5bycdd_/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-s5bycdd_/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-t3_mpbah/install-record.txt --single-version-externally-managed --compile --install-headers /root/.local/share/virtualenvs/PoshC2-KGSTtxLR/include/site/python3.8/psycopg2
[pipenv.exceptions.InstallError]:          cwd: /tmp/pip-install-s5bycdd_/psycopg2/
[pipenv.exceptions.InstallError]:     Complete output (42 lines):
[pipenv.exceptions.InstallError]:     running install
[pipenv.exceptions.InstallError]:     running build
[pipenv.exceptions.InstallError]:     running build_py
[pipenv.exceptions.InstallError]:     creating build
[pipenv.exceptions.InstallError]:     creating build/lib.linux-x86_64-3.8
[pipenv.exceptions.InstallError]:     creating build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/compat.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
[pipenv.exceptions.InstallError]:     warning: build_py: byte-compiling is disabled, skipping.
[pipenv.exceptions.InstallError]:     
[pipenv.exceptions.InstallError]:     running build_ext
[pipenv.exceptions.InstallError]:     building 'psycopg2._psycopg' extension
[pipenv.exceptions.InstallError]:     creating build/temp.linux-x86_64-3.8
[pipenv.exceptions.InstallError]:     creating build/temp.linux-x86_64-3.8/psycopg
[pipenv.exceptions.InstallError]:     x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.8.5 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120001 -DHAVE_LO64=1 -I/root/.local/share/virtualenvs/PoshC2-KGSTtxLR/include -I/usr/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statement
[pipenv.exceptions.InstallError]:     In file included from psycopg/psycopgmodule.c:28:
[pipenv.exceptions.InstallError]:     ./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
[pipenv.exceptions.InstallError]:        36 | #include <libpq-fe.h>
[pipenv.exceptions.InstallError]:           |          ^~~~~~~~~~~~
[pipenv.exceptions.InstallError]:     compilation terminated.
[pipenv.exceptions.InstallError]:     
[pipenv.exceptions.InstallError]:     It appears you are missing some prerequisite to build the package from source.
[pipenv.exceptions.InstallError]:     
[pipenv.exceptions.InstallError]:     You may install a binary package by installing 'psycopg2-binary' from PyPI.
[pipenv.exceptions.InstallError]:     If you want to install psycopg2 from source, please install the packages
[pipenv.exceptions.InstallError]:     required for the build and try again.
[pipenv.exceptions.InstallError]:     
[pipenv.exceptions.InstallError]:     For further information please check the 'doc/src/install.rst' file (also at
[pipenv.exceptions.InstallError]:     <https://www.psycopg.org/docs/install.html>).
[pipenv.exceptions.InstallError]:     
[pipenv.exceptions.InstallError]:     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
[pipenv.exceptions.InstallError]:     ----------------------------------------
[pipenv.exceptions.InstallError]: ERROR: Command errored out with exit status 1: /root/.local/share/virtualenvs/PoshC2-KGSTtxLR/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-s5bycdd_/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-s5bycdd_/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-t3_mpbah/install-record.txt --single-version-externally-managed --compile --install-headers /root/.local/share/virtualenvs/PoshC2-KGSTtxLR/include/site/python3.8/psycopg2 Check the logs for full command output.
ERROR: Couldn't install package: psycopg2
 Package installation failed...
  ☤  ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/1 — 00:00:02
kali@kali:/opt/PoshC2$ 

Noted, thanks @wesinator , added a PR for this here: #147

Actually libpq-dev is already in the install file 🤔 which provides the libpq-fe.h header. @wesinator did your install script error at all?

commented

Actually libpq-dev is already in the install file 🤔 which provides the libpq-fe.h header. @wesinator did your install script error at all?

Yea I noticed that which was odd
I don't remember I no longer have the output - I think that was the main error