Skip to content

Instantly share code, notes, and snippets.

@Jasemalsadi
Last active April 21, 2023 03:33
Show Gist options
  • Save Jasemalsadi/7c894031e8ecf46d102eb8689df48d5a to your computer and use it in GitHub Desktop.
Save Jasemalsadi/7c894031e8ecf46d102eb8689df48d5a to your computer and use it in GitHub Desktop.
PHPSTORM remote debugging with pivoting for OSWE Web Apps

Setup Port forwarding on the debugged machine:

ssh student@atutor

echo -e "\nGatewayPorts yes \n" | sudo tee -a /etc/ssh/sshd_config && sudo service sshd restart

Set up proxy Server on the Kali VM/VPN machine :

echo -e "\nGatewayPorts yes \n" >> /etc/ssh/sshd_config && service sshd restart

sudo nano/etc/squid/squid.conf

http_port 8888

acl container src 192.168.143.0/24

http_access allow container

service squid restart

ssh -R8888:localhost:8888 -R9000:localhost:9000 -vvv student@atutor

Set up SSH remote port Forwarding on the PHPSTORM installed machine:

ssh -R 9000:localhost:9000 -vvv [email protected]

Where 192.168.115.131 is the Kali VM IP

Set up and install debugging tools on the debugged machine:

ssh student@atutor

sudo nano /etc/apt/apt.conf

Acquire::http::Proxy "http://localhost:8888";

Acquire::https::Proxy "https://localhost:8888";

sudo apt-get update

sudo apt-get install php5-dev

sudo apt-get install php5-xdebug

sudo updatedb

locate xdebug.so

/usr/lib/php5/20131226/xdebug.so

sudo nano /etc/php5/apache2/conf.d/20-xdebug.ini

zend_extension=/usr/lib/php5/20131226/xdebug.so

xdebug.remote_host = 127.0.0.1

xdebug.remote_enable = 1

xdebug.remote_port = 9000

;xdebug.remote_handler = dbgp

;xdebug.remote_mode = req

;xdebug.profiler_enable=0

;xdebug.profiler_enable_trigger=1

xdebug.remote_autostart=1

;xdebug.idekey=PHPSTORM

xdebug.remote_log="/tmp/xdebug.log"

sudo service apache2 restart

sudo systemctl restart nginx

php --version

PHP 5.6.40-0+deb8u12 (cli) (built: Jun 28 2020 09:37:30)

Copyright (c) 1997-2016 The PHP Group

Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Setup xdebug plugin on firefox Kali VM :

Right now, we did everything, we need to install xdebug helper plugin in Firefox and enable it, so it can add the XDEBUG_SESSION=PHPSTORM; as cookie value automatically.

Setup PHPSTORM xdebug listener on the PHPSTORM installed machine:

Using PHPStorm, Add mapping path of the file on disk and absolute server path.

Then,enable the debugger icon.

Alternate image text

Then click this icon:

Alternate image text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment