Jump to content

Sending output to a device driver

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
What would happen if you typed something like:


$ cat text.txt > /dev/console


Would it overwrite the content of the device driver, or would it tell the device to do something, like say, display the contents of text.txt on the terminal? I want to explore this, because I think I could write some pretty powerful applications by sending output to device drivers, but I'm afraid I'll mess them up (if I have permission on them).
Life's too short to be cool. Be a nerd.

#2
TimVim

TimVim

    Newbie

  • Members
  • PipPip
  • 10 posts
I was bold enough to type your trojan into my console and apparently it doesn't do anything.

LimpPimp:~ timvim$ cat text.txt > /dev/console
cat: text.txt: No such file or directory
LimpPimp:~ timvim$ 


#3
saeras

saeras

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
Cat('s) always strike when you least expect it. :3
Posted Image

#4
ETShost

ETShost

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
When writing to a device file, what happens depends on the device and how the driver is written.
For example, writing to your sound device will actually play sound(of course that sound would have to be uncompressed first, otherwise it wouldn't sound very great). Writing to a modem's device file will give it instructions to dial a number(if you know what commands to write to it).

Also in your example, writing to someones console device would cause the text you wrote to appear on their screen. However instead of writing to /dev/console you would write to their pseudo-terminal(AKA a pty). You can usually find out which pty a terminal device a session is attached to using the who command. You can open up multiple terminals a output text to different ones to see for yourself.


zpowers@zpowers-devel:~$ who

zpowers  tty7         2010-02-16 09:43 (:0)

zpowers  pts/0        2010-02-18 11:33 (:0.0)

zpowers  pts/2        2010-02-18 12:57 (:0.0)

zpowers  pts/3        2010-02-18 12:59 (:0.0)

zpowers@zpowers-devel:~$ w

10:59:36 up 3 days,  1:16,  4 users,  load average: 0.06, 0.01, 0.00

USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

zpowers  tty7     :0               Tue09    3days 43:12   0.28s gnome-session

zpowers  pts/0    :0.0             Thu11   19:01   5.75s  5.65s ssh acm.umflint.edu

zpowers  pts/2    :0.0             Thu12    1:29m  0.11s  0.11s bash

zpowers  pts/3    :0.0             Thu12    0.00s  0.10s  0.01s w


zpowers@zpowers-devel:~$ ls -l /dev/pts

total 0

crw--w---- 1 zpowers tty  136, 0 2010-02-19 10:59 0

crw--w---- 1 zpowers tty  136, 1 2010-02-16 10:01 1

crw--w---- 1 zpowers tty  136, 2 2010-02-19 09:34 2

crw--w---- 1 zpowers tty  136, 3 2010-02-19 10:59 3

c--------- 1 root    root   5, 2 2010-02-16 09:45 ptmx

zpowers@zpowers-devel:~$ echo Hi! > /dev/pts/3

Hi!

zpowers@zpowers-devel:~$


In this particular case I was using pseudo-terminal session number 3, and writing to the device caused text to appear in my terminal.

Generally I wouldn't write to just any device without knowing what you are doing, or what will happen when you write to it. Bad things can happen(like if you were write directly to your RAM or worst cause more permanent damage by writing to your hard drive).
ETShost .com - Exceeding Innovation
Dedicated ServersVPS • Web Hosting
24/7 Support | 1-866-259-2934