Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pwnlib/util/proc/status error #1163

Closed
0xling opened this issue May 31, 2018 · 2 comments
Closed

pwnlib/util/proc/status error #1163

0xling opened this issue May 31, 2018 · 2 comments

Comments

@0xling
Copy link

0xling commented May 31, 2018

in pwnlib/util/proc.py the Fucntion status. when the line is an empty line, the line.index(':') will raise an Exception.

       with open('/proc/%d/status' % pid) as fd:
            for line in fd:
                i = line.index(':')
                key = line[:i]
                val = line[i + 2:-1] # initial :\t and trailing \n
                out[key] = val

In my ubuntu 1604, the status file just has an empty line.

$ cat /proc/self/status
Name:	cat
State:	R (running)
Tgid:	19376
Ngid:	0
Pid:	19376
PPid:	19347
TracerPid:	0
Uid:	1000	1000	1000	1000
Gid:	1000	1000	1000	1000
FDSize:	64
Groups:	4 24 27 30 46 113 128 1000 
NStgid:	19376
NSpid:	19376
NSpgid:	19376
NSsid:	19347
VmPeak:	    9184 kB
VmSize:	    9184 kB
VmLck:	       0 kB
VmPin:	       0 kB
VmHWM:	     696 kB
VmRSS:	     696 kB
VmData:	     320 kB
VmStk:	     132 kB
VmExe:	      48 kB
VmLib:	    1944 kB
VmPTE:	      40 kB
VmPMD:	      12 kB
VmSwap:	       0 kB
HugetlbPages:	       0 kB
Threads:	1
SigQ:	1/11699
SigPnd:	0000000000000000
ShdPnd:	0000000000000000
SigBlk:	0000000000000000
SigIgn:	0000000000000000
SigCgt:	0000000000000000
CapInh:	0000000000000000
CapPrm:	0000000000000000
CapEff:	0000000000000000
CapBnd:	0000003fffffffff
CapAmb:	0000000000000000
Seccomp:	0

Speculation_Store_Bypass:	vulnerable
Cpus_allowed:	ffffffff,ffffffff
Cpus_allowed_list:	0-63
Mems_allowed:	00000000,00000001
Mems_allowed_list:	0
voluntary_ctxt_switches:	0
nonvoluntary_ctxt_switches:	1

the version of my ubuntu

$ uname -a
Linux ubuntu64 4.4.0-127-generic #153-Ubuntu SMP Sat May 19 10:58:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

I don't know why there existed an empty line, but I think here should add two line code to check empty line.

                if line.strip() == '':
                    continue

And also in the proc.py, I found the function pidof(target), there are 9 space leave in the following code.

    elif isinstance(target, tubes.sock.sock):
         local  = target.sock.getsockname()
         remote = target.sock.getpeername()

         def match(c):
             return (c.raddr, c.laddr, c.status) == (local, remote, 'ESTABLISHED')

         return [c.pid for c in psutil.net_connections() if match(c)]
@zachriggle
Copy link
Member

There's an open pull request for this, see #1159

@zachriggle
Copy link
Member

This should be fixed in the stable branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants