Keylogging on Linux as a limited user

Discussion in 'all things UNIX' started by Gullible Jones, Jun 8, 2012.

Thread Status:
Not open for further replies.
  1. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    A server wouldn't be relevant in this situation as it would (likely) not have a GUI.

    And like I said in the first post Wayland solves this keylogging issue.

    I don't think it can be dismissed just because no one's posted exploit code that specifically does this. It's hardly surprising as servers are the typical targets and this doesn't apply to those.

    It can still easily affect a user, which the demostration shows.
     
    Last edited: Jun 9, 2012
  2. BrandiCandi

    BrandiCandi Guest

  3. tlu

    tlu Guest

    Doesn't work here. After entering xinput test ID and entering something in Firefox or kate, nothing is shown in the terminal.
     
  4. vasa1

    vasa1 Registered Member

    Joined:
    May 1, 2010
    Posts:
    4,417
    Which ID did you enter?
    Code:
    xinput list
    ⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
    ⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
    ⎜   ↳ Dell Dell USB Optical Mouse             	id=11	[slave  pointer  (2)]
    ⎜   ↳ PS/2 Mouse                              	id=13	[slave  pointer  (2)]
    ⎜   ↳ AlpsPS/2 ALPS GlidePoint                	id=14	[slave  pointer  (2)]
    ⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
        ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
        ↳ Video Bus                               	id=6	[slave  keyboard (3)]
        ↳ Power Button                            	id=7	[slave  keyboard (3)]
        ↳ Sleep Button                            	id=8	[slave  keyboard (3)]
        ↳ HID 413c:8161                           	id=9	[slave  keyboard (3)]
        ↳ Integrated_Webcam_1.3M                  	id=10	[slave  keyboard (3)]
        ↳ AT Translated Set 2 keyboard            	id=12	[slave  keyboard (3)]
        ↳ Dell WMI hotkeys                        	id=15	[slave  keyboard (3)]
    
    I entered "12" and see input when I type stuff into geany or into Firefox while typing this reply, for example..
     
  5. vasa1

    vasa1 Registered Member

    Joined:
    May 1, 2010
    Posts:
    4,417
    And even with Chrome. My Chrome isn't AppArmored while Firefox is.
     
  6. tlu

    tlu Guest

    Ah, sorry, I had used the wrong ID :oops: Now it works.
     
  7. Since I think this topic deserves resuscitation, here's some sample strace output from 'xinput test':

    Code:
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O<\22\0\377&F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   60 \n", 16key press   60 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P<\22\0\202'F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 60 \n", 16key release 60 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O6\22\0\205'F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   54 \n", 16key press   54 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P6\22\0\321'F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 54 \n", 16key release 54 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O4\22\0\357'F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   52 \n", 16key press   52 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P4\22\0s(F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 52 \n", 16key release 52 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O$\22\0\256(F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   36 \n", 16key press   36 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P$\22\0\r)F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 36 \n", 16key release 36 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O@\22\0y*F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   64 \n", 16key press   64 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O\27\22\0\323*F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\10\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   23 \n", 16key press   23 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P\27\22\0{+F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\10\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 23 \n", 16key release 23 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P@\22\0009-F\0\252\0\0\0\252\0\0\0\332\6\304\0\321\3f\1\321\3f\1\10\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 64 \n", 16key release 64 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O@\22\0\374bF\0\252\0\0\0\252\0\0\0\332\6\304\0F\1m\1F\1m\1\0\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   64 \n", 16key press   64 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "O\27\22\0\211cF\0\252\0\0\0\252\0\0\0\332\6\304\0F\1m\1F\1m\1\10\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key press   23 \n", 16key press   23 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P\27\22\0YdF\0\252\0\0\0\252\0\0\0\332\6\304\0F\1m\1F\1m\1\10\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 23 \n", 16key release 23 
    )       = 16
    poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
    recv(3, "P@\22\0\326dF\0\252\0\0\0\252\0\0\0\332\6\304\0F\1m\1F\1m\1\10\0\1\r", 4096, 0) = 32
    recv(3, 0x8efeae0, 4096, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    write(1, "key release 64 \n", 16key release 64 
    )       = 16
    
    What do you guys make of it?
     
  8. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,224
    Without telling us what fd=3 is, it's hard to tell.
    However, nothing interesting there. You need more than just system calls.
    Mrk
     
  9. Not sure what fd=3 is. How would I get "more than just system calls"?
     
  10. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,224
    Other tools. File descriptor 3, could be a local file, could be a socket.
    There's ltrace, netstat, there's gdb, a whole lot.
    But no point doing that if you don't understand the output.
    Just enjoy yourself!
    Dedoimedo
     
  11. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    To answer your question from the now-closed topic, it's just as easy as sniffing. The massive issue here being that any program with X access can interact with terminals open on the system etc.

    Let's say I have Program A and I block its access to open /path/to/file.txt.

    I then open up a terminal.

    Program A can use X to type into that terminal "/path/to/file.txt" and voila.
     
  12. Okay, resurrecting this because I'm interested in the keystroke injection thing. How easy would that be to accomplish? And wouldn't it effectively nullify DAC and MAC restrictions, in the same way as a shatter attack on Windows NT?
     
  13. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    Yes, it does. Sort of.

    If you're an attacker and the user has a terminal open you can basically do anything that a regular user can do via their shell. Of course, the user would see you typing and all that but that doesn't seem hard to get around.

    And if the user doesn't happen to have a terminal open you can do less - you could type in a URL or whatever but it's really unpredictable, which is why an attack like this is unlikely although obviously very possible.
     
  14. If you knew what you were doing you could probably fuzz some applications, I would think.

    But wow. That's pretty bad. I think I understand now what Rutkowska & company are talking about when they say that no current desktop OS is "reasonably secure."
     
  15. Hungry Man

    Hungry Man Registered Member

    Joined:
    May 11, 2011
    Posts:
    9,146
    To be honest it's the biggest issue I see with Linux security and pretty much the only one that can't be solved in any simple way (like ~Phrase removed~ ASLR just means you take a few minutes to recompile the kernel with PaX, or set up Apparmor, etc).
     
    Last edited by a moderator: Nov 3, 2012
  16. Cudni

    Cudni Global Moderator

    Joined:
    May 24, 2009
    Posts:
    6,963
    Location:
    Somethingshire
  17. BTW, another thought: could Javascript executed in a browser be used to capture keystrokes? Or would the JS sandbox in most browsers not permit that?
     
  18. NGRhodes

    NGRhodes Registered Member

    Joined:
    Jun 23, 2003
    Posts:
    2,381
    Location:
    West Yorkshire, UK
    Only within the same [browser] process [for a correctly working browser].

    Cheer, Nick
     
  19. That at least is good to know... Thanks.
     
  20. ITSEC ds

    ITSEC ds Registered Member

    Joined:
    Oct 8, 2012
    Posts:
    1
    Location:
    Italy
  21. Exactly like that. And for once, good on Microsoft for actually doing things right out of the box!
     
  22. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,066
    Location:
    Canada
    Well, almost right. Better than Linux but that part 2 demo shows that a keylogger running with standard rights can still intercept keystrokes from an application (in this case a browser) running with the same standard rights, since the integrity levels are the same. This is probably where the most damage will occur because banking, Paypal and other highly sensitive online-applied credentials can be stolen.

    I think what it really comes down to is don't install keyloggers in the first place. On a side note this is why I'm a fan of outbound application firewall restrictions.
     
  23. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Linux = locally induced, running the keylogger script locally, so ?
     
  24. So a browser exploit (or IM, or whatever) could install it, just like in Windows. The only reason you haven't seen it happen is the limited user base.
     
  25. linuxforall

    linuxforall Registered Member

    Joined:
    Feb 6, 2010
    Posts:
    2,137
    But isn't the server space thats dominated by Linux more prone to hack attacks so in a sense, the limited user base theory doesn't apply really.
     
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.