Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Ethical Hacking from Scratch

You're reading from   Python Ethical Hacking from Scratch Think like an ethical hacker, avoid detection, and successfully develop, deploy, detect, and avoid malware

Arrow left icon
Product type Paperback
Published in Jun 2021
Publisher Packt
ISBN-13 9781838829506
Length 214 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Fahad Ali Sarwar Fahad Ali Sarwar
Author Profile Icon Fahad Ali Sarwar
Fahad Ali Sarwar
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Section 1: The Nuts and Bolts of Ethical Hacking – The Basics
2. Chapter 1: Introduction to Hacking FREE CHAPTER 3. Chapter 2: Getting Started – Setting Up a Lab Environment 4. Section 2: Thinking Like a Hacker – Network Information Gathering and Attacks
5. Chapter 3: Reconnaissance and Information Gathering 6. Chapter 4: Network Scanning 7. Chapter 5: Man in the Middle Attacks 8. Section 3: Malware Development
9. Chapter 6: Malware Development 10. Chapter 7: Advanced Malware 11. Chapter 8: Post Exploitation 12. Chapter 9: System Protection and Perseverance 13. Other Books You May Enjoy

Running commands remotely on the victim's machine

We have already seen in Chapter 3, Reconnaissance and Information Gathering (in the Creating a Python script section), how to run commands on a computer using Python. We will build on that knowledge to create a malware that will take commands and execute them on a victim's machine. Our previous program just sends one message to the victim and exits. This time, we will modify the program to do much more than that.

Open a new project on the Kali machine to execute commands on the victim's machine and create a new file. Let's start by establishing a connection:

import socket
if __name__ == "__main__":
    hacker_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    IP = "192.168.74.128"
    Port = 8008
    socket_address = (IP, Port)
    hacker_socket.bind(socket_address)
  ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime