zoukankan      html  css  js  c++  java
  • rex 上传文件并远程执行

    Rex::Commands::File - Transparent File Manipulation:
    
    
    名称
    
    Rex::Commands::File - Transparent File Manipulation
    
    
    task "read-passwd2", "192.168.137.3", sub {
       say cat "/etc/passwd";
     };
    
    [root@node01 Rex]# rex "read-passwd2" | grep tlcb
    [2017-09-12 02:16:08] WARN - Please use only the following characters for task names:
    [2017-09-12 02:16:08] WARN -   A-Z, a-z, 0-9 and _
    [2017-09-12 02:16:08] WARN - Also the task should start with A-Z or a-z
    [2017-09-12 02:16:08] WARN - You can disable this warning by setting feature flag: disable_taskname_warning
    [2017-09-12 02:16:08] INFO - Running task read-passwd2 on 192.168.137.3
    tlcb:x:504:504::/home/tlcb:/bin/bash
    [2017-09-12 02:16:09] INFO - All tasks successful on all hosts
    [root@node01 Rex]# 
    
    file($file_name, %options)
    
    这个函数是Install file命令的缩写,请使用这个函数来上传文件:
    
    task "prepare01", "192.168.137.3", sub {
       file "/root/sbin/a1.pl",
       source => "/root/Rex/a1.pl";
    };
    [root@node01 Rex]# rex prepare01
    
    文件从本地的/root/Rex/a1.pl 上传到/root/sbin/a1.pl
    
    
    task "prepare01", "192.168.137.3", sub {
       file "/home/mqm/xbin/test.sh",
       source => "/root/Rex/test.sh",
       mode => 755,  
       owner  => "mqm",  
       group  => "mqm";
       my $output = run "/home/mqm/xbin/test.sh";  
       say $output;  
    
    };
    
    上传文件,执行命令
    
    node2:/home/mqm/xbin#ls -ltr
    total 33548
    -rw-r--r-- 1 mqm mqm 34344960 Mar 28  2017 mqm.tar
    drwxrwxr-x 3 mqm mqm     4096 Aug 24 22:02 mqm
    -rwxr-xr-x 1 mqm mqm       35 Sep 12 02:41 test.sh
    
    权限为755 数组为mqm:mqm
    
    
    task "prepare01", "192.168.137.3", sub {
       file "/home/mqm/xbin/test.sh",
       source => "/root/Rex/test.sh",
       mode => 700,  
       owner  => "mqm",  
       group  => "mqm";
       my $output = run "/home/mqm/xbin/test.sh";  
       say $output;  
    
    };
    
    node2:/home/mqm/xbin#ls -ltr
    total 33548
    -rw-r--r-- 1 mqm mqm 34344960 Mar 28  2017 mqm.tar
    drwxrwxr-x 3 mqm mqm     4096 Aug 24 22:02 mqm
    -rwx------ 1 mqm mqm       35 Sep 12 02:41 test.sh
    

  • 相关阅读:
    技术文章阅读-Pi-Hole < 4.3.2 Command Injection & PrivEsc (CVE-2019-13051)
    技术文章阅读-d-link-routers-found-vulnerable-rce
    技术文章阅读-蜂网互联企业级路由器v4.31密码泄露漏洞
    使用mkcert工具自签https证书
    查询给定时间是否在当前周
    nodeJS 一些笔记
    手机端页面布局方案
    关于HTML5的应用缓存功能
    将伪数组转换为数组的方法
    Cookies的使用之购物车的实现
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349493.html
Copyright © 2011-2022 走看看