Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Jan 27, 2025
1 parent 3b2795e commit b641f3a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pwnshop/templates/peer-discovery.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pathlib
import psutil

# This function retrieves the path of the process that is on the
# This function determines the process that is on the
# other side of the file descriptor we pass in.
def peer_path(fd):
def peer_process_of(fd):
server_connection = next(
connection
for connection in psutil.Process().connections()
Expand All @@ -15,14 +15,13 @@ def peer_path(fd):
if connection.raddr == server_connection.laddr
and connection.laddr == server_connection.raddr
)
client_process = psutil.Process(client_connection.pid)
return client_process.exe()
return psutil.Process(client_connection.pid)

# This function returns the filename of a peer process for a given
# file descriptor, verifying that the path is owned by root and
# not open to shenanigans.
def trusted_peer_name(fd):
client_path = pathlib.Path(peer_path(fd))
def name_of_program_for(process):
client_path = pathlib.Path(process.exe())
for p in reversed(client_path.parents):
if not p.owner() == "root":
return None
Expand Down

0 comments on commit b641f3a

Please sign in to comment.