V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
CoderLife
V2EX  ›  程序员

阿里云被植入了挖矿程序, 请大佬帮个忙啊

  •  
  •   CoderLife · 2019-12-23 12:50:54 +08:00 · 8488 次点击
    这是一个创建于 1557 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前还不知道怎么引入的.

    请各位大神帮忙解一下.

    ps aux

    postgres  9961  0.0  0.0   2236    72 ?        Ss   11:56   0:00 fE8fEp
    postgres 11962  102 61.7 2432548 2396640 ?     Ssl  12:18  14:57 IS47Dj
    

    阿里云报告

    恶意进程(云查杀)-挖矿程序

    该告警由如下引擎检测发现:
    中控 IP:101.64.182.145
    中控端口:443
    进程路径:/tmp/363188e0133843515b9d6f1c487f017c (deleted)
    命令行参数:IS47Dj
    

    杀了还是会自启动

    我的 ps aux

    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         1  0.0  0.0  51724  2596 ?        Ss   Oct29  10:18 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
    root         2  0.0  0.0      0     0 ?        S    Oct29   0:00 [kthreadd]
    root         3  0.0  0.0      0     0 ?        S    Oct29   0:10 [ksoftirqd/0]
    root         5  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kworker/0:0H]
    root         7  0.0  0.0      0     0 ?        S    Oct29   0:02 [migration/0]
    root         8  0.0  0.0      0     0 ?        S    Oct29   0:00 [rcu_bh]
    root         9  0.0  0.0      0     0 ?        R    Oct29  44:01 [rcu_sched]
    root        10  0.0  0.0      0     0 ?        S<   Oct29   0:00 [lru-add-drain]
    root        11  0.0  0.0      0     0 ?        S    Oct29   0:25 [watchdog/0]
    root        12  0.0  0.0      0     0 ?        S    Oct29   3:51 [watchdog/1]
    root        13  0.0  0.0      0     0 ?        S    Oct29   0:02 [migration/1]
    root        14  0.0  0.0      0     0 ?        S    Oct29   0:11 [ksoftirqd/1]
    root        16  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kworker/1:0H]
    root        18  0.0  0.0      0     0 ?        S    Oct29   0:00 [kdevtmpfs]
    root        19  0.0  0.0      0     0 ?        S<   Oct29   0:00 [netns]
    root        20  0.0  0.0      0     0 ?        S    Oct29   0:01 [khungtaskd]
    root        21  0.0  0.0      0     0 ?        S<   Oct29   0:00 [writeback]
    root        22  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kintegrityd]
    root        23  0.0  0.0      0     0 ?        S<   Oct29   0:00 [bioset]
    root        24  0.0  0.0      0     0 ?        S<   Oct29   0:00 [bioset]
    root        25  0.0  0.0      0     0 ?        S<   Oct29   0:00 [bioset]
    root        26  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kblockd]
    root        27  0.0  0.0      0     0 ?        S<   Oct29   0:00 [md]
    root        28  0.0  0.0      0     0 ?        S<   Oct29   0:00 [edac-poller]
    root        29  0.0  0.0      0     0 ?        S<   Oct29   0:00 [watchdogd]
    root        36  0.0  0.0      0     0 ?        S    Oct29   2:57 [kswapd0]
    root        37  0.0  0.0      0     0 ?        SN   Oct29   0:00 [ksmd]
    root        38  0.0  0.0      0     0 ?        SN   Oct29   0:13 [khugepaged]
    root        39  0.0  0.0      0     0 ?        S<   Oct29   0:00 [crypto]
    root        47  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kthrotld]
    root        49  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kmpath_rdacd]
    root        50  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kaluad]
    root        51  0.0  0.0      0     0 ?        S<   Oct29   0:00 [kpsmoused]
    root        52  0.0  0.0      0     0 ?        S<   Oct29   0:00 [ipv6_addrconf]
    root        65  0.0  0.0      0     0 ?        S<   Oct29   0:00 [deferwq]
    root        97  0.0  0.0      0     0 ?        S    Oct29   0:05 [kauditd]
    root       232  0.0  0.0      0     0 ?        S<   Oct29   0:00 [ata_sff]
    root       254  0.0  0.0      0     0 ?        S    Oct29   0:00 [scsi_eh_0]
    root       260  0.0  0.0      0     0 ?        S<   Oct29   0:00 [scsi_tmf_0]
    root       263  0.0  0.0      0     0 ?        S    Oct29   0:00 [scsi_eh_1]
    root       264  0.0  0.0      0     0 ?        S<   Oct29   0:00 [scsi_tmf_1]
    root       305  0.0  0.0      0     0 ?        S<   Oct29   0:00 [ttm_swap]
    root       317  0.0  0.0      0     0 ?        S<   Oct29   0:42 [kworker/0:1H]
    root       323  0.0  0.0      0     0 ?        S<   Oct29   0:13 [kworker/1:1H]
    root       328  0.0  0.0      0     0 ?        S    Oct29   1:45 [jbd2/vda1-8]
    root       329  0.0  0.0      0     0 ?        S<   Oct29   0:00 [ext4-rsv-conver]
    redis      375  0.1  0.1 310892  6812 ?        Ssl  Nov08  65:03 /usr/bin/redis-server 127.0.0.1:6379
    root       397  0.0  0.8 149876 32136 ?        Ss   Oct29   1:38 /usr/lib/systemd/systemd-journald
    root       421  0.0  0.0  44460   956 ?        Ss   Oct29   0:00 /usr/lib/systemd/systemd-udevd
    root       474  0.0  0.0  55520   692 ?        S<sl Oct29   0:24 /sbin/auditd
    root       577  0.0  0.0      0     0 ?        S<   Oct29   0:00 [nfit]
    root       600  0.0  0.0  26612  1340 ?        Ss   Oct29   1:29 /usr/lib/systemd/systemd-logind
    polkitd    606  0.0  0.2 612328  9220 ?        Ssl  Oct29   1:11 /usr/lib/polkit-1/polkitd --no-debug
    dbus       607  0.0  0.0  58228  1260 ?        Ss   Oct29   3:11 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
    chrony     619  0.0  0.0 117908  1160 ?        S    Oct29   0:18 /usr/sbin/chronyd
    root       661  0.0  0.0  25904   204 ?        Ss   Oct29   0:00 /usr/sbin/atd -f
    root       663  0.0  0.0 126316  1084 ?        Ss   Oct29   0:22 /usr/sbin/crond -n
    root       673  0.0  0.0 110104   128 ttyS0    Ss+  Oct29   0:00 /sbin/agetty --keep-baud 115200,38400,9600 ttyS0 vt220
    root       674  0.0  0.0 110104   132 tty1     Ss+  Oct29   0:00 /sbin/agetty --noclear tty1 linux
    root       840  0.0  0.0 107464  1996 ?        Ss   Oct29   0:00 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient--eth0.lease -pf /var/run/dhclient-eth0.pid -H iZ8vb1nz5l71xucapbkndaZ eth0
    root       901  0.0  0.3 573920 13260 ?        Ssl  Oct29   9:42 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
    root       905  0.0  0.3 451608 13688 ?        Ssl  Oct29   7:20 /usr/sbin/rsyslogd -n
    root      1087  0.0  0.0      0     0 ?        R    10:35   0:01 [kworker/1:1]
    root      1115  0.0  0.0 112864  1256 ?        Ss   Oct29   0:05 /usr/sbin/sshd -D
    root      1413  0.0  0.1 122428  4668 ?        Ss   Oct29   0:00 nginx: master process nginx
    root      5011  0.0  0.1 157260  5056 ?        Ss   11:23   0:00 sshd: root@pts/1
    root      5013  0.0  0.0 115572  1280 pts/1    Ss+  11:23   0:00 -bash
    root      7006  0.0  0.0  32528  2992 ?        S<sl Nov15  30:00 /usr/local/aegis/aegis_update/AliYunDunUpdate
    root      9471  0.0  0.0      0     0 ?        S    11:50   0:00 [kworker/0:1]
    root      9838  0.0  0.1 154652  4752 ?        Ss   11:55   0:00 sshd: root@pts/0
    root      9841  0.0  0.0 115572  1252 pts/0    Ss+  11:55   0:00 -bash
    postgres  9961  0.0  0.0   2236    72 ?        Ss   11:56   0:00 fE8fEp
    postgres 10931  0.2  0.0  16008   104 ?        Ssl  12:08   0:05 tracepath
    postgres 11962  102 61.7 2432548 2396640 ?     Ssl  12:18  20:12 IS47Dj
    root     12097  0.0  0.0      0     0 ?        S    12:20   0:00 [kworker/1:2]
    root     12500  0.0  0.1 154652  5568 ?        Ss   12:25   0:00 sshd: root@pts/2
    root     12503  0.0  0.0 115572  2184 pts/2    Ss+  12:25   0:00 -bash
    postgres 12782  0.0  0.3 396672 12344 ?        Ss   Dec10   1:18 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
    postgres 12785  0.0  0.0 249468  1580 ?        Ss   Dec10   0:00 postgres: logger   
    postgres 12787  0.0  0.6 396796 27100 ?        Ss   Dec10   0:05 postgres: checkpointer   
    postgres 12788  0.0  0.1 396672  6728 ?        Ss   Dec10   0:15 postgres: background writer   
    postgres 12789  0.0  0.1 396672  5608 ?        Ss   Dec10   0:38 postgres: walwriter   
    postgres 12790  0.0  0.0 397224  2744 ?        Ss   Dec10   0:36 postgres: autovacuum launcher   
    postgres 12791  0.0  0.0 251872  1872 ?        Ss   Dec10   1:16 postgres: stats collector   
    postgres 12792  0.0  0.0 397088  2112 ?        Ss   Dec10   0:01 postgres: logical replication launcher   
    root     13401  0.0  0.0      0     0 ?        S    Dec22   0:01 [kworker/u4:1]
    root     14259  0.0  0.0      0     0 ?        S    12:35   0:00 [kworker/1:0]
    root     14447  0.5  0.1 154652  5568 ?        Ss   12:38   0:00 sshd: root@pts/3
    root     14450  0.0  0.0 115572  2104 pts/3    Ss   12:38   0:00 -bash
    root     14470  0.0  0.0 155332  1816 pts/3    R+   12:38   0:00 ps aux
    root     24612  0.0  0.0  41828  2596 ?        Ssl  Nov15  23:48 /usr/sbin/aliyun-service
    root     26707  0.0  0.0      0     0 ?        S    09:00   0:00 [kworker/0:2]
    root     26894  0.0  0.0      0     0 ?        S    01:21   0:00 [kworker/u4:0]
    root     27890  3.2  0.3 137752 14064 ?        S<sl Dec21  96:39 /usr/local/aegis/aegis_client/aegis_10_75/AliYunDun
    nginx    31630  0.0  0.1 123032  6340 ?        S    Dec21   0:22 nginx: worker process
    nginx    31631  0.0  0.1 123304  6580 ?        S    Dec21   0:30 nginx: worker process
    
    第 1 条附言  ·  2019-12-23 13:21:56 +08:00
    感觉应该是通过 postgres 来的, 最早的时候 Postgres 弱密码, 没有绑 Ip,
    第 2 条附言  ·  2019-12-23 13:34:53 +08:00

    根据阿里云的报告:

    进程异常行为-可疑编码命令待处理
    备注处理
    该告警由如下引擎检测发现:
    用户名:postgres
    命令行:sh -c echo ZXhlYy......p9CngK |base64 -d|bash
    

    解开, 发现里面有一个访问这些列表:

    tor2web.io
    onion.to
    onion.mn
    onion.in.net
    4tor.ml
    d2web.org
    onion.glass
    civiclink.network
    tor2web.su
    onion.ly
    onion.pet
    onion.ws
    

    这些域名已加入hosts 再看效果

    第 3 条附言  ·  2019-12-24 10:03:27 +08:00

    问题已初步解决 没有重装系统, 因为重装太麻烦, 东西太多.
    大概说一下步骤:

    1. 通过阿里云的报告, 把里面访问的中控机加到出口禁止列表
    2. 报告里会写执行了哪些脚本, 都是base64的, 解开, 把访问的域名, 加到hosts里
    3. 脚本先从域名下载文件, 然后通过拼凑文件名保存下来, 全文去搜, 一一删除
    4. 添加安全访问策略, ssh, postgres, mysql, redis, 只能本机可以访问, posgres nologin.

    想了想原因, 可能引入的原因:

    1. 之前有一段时间redis随便访问, 没有密码
    2. Postgres可以远程访问, 弱密码
    3. 之前用过盗版的Zoc7, xcl**t.in*o上下载的, 因为lrzsz用起来方便, 现已删除 老实的用scp

    多谢各位大佬的关注.

    39 条回复    2019-12-24 20:54:54 +08:00
    msg7086
        1
    msg7086  
       2019-12-23 12:58:39 +08:00
    重装啊,难道你打算查杀?
    CoderLife
        2
    CoderLife  
    OP
       2019-12-23 13:03:44 +08:00
    @msg7086 重新好吓人, 里面的东西太多了
    cyannnna
        3
    cyannnna  
       2019-12-23 13:12:48 +08:00
    没快照或者备份么?
    luozic
        4
    luozic  
       2019-12-23 13:14:39 +08:00
    看到 redis 很有可能是通过 redis 开放端口入侵的。
    MadHouse
        5
    MadHouse  
       2019-12-23 13:17:38 +08:00 via Android
    直接 kill 不行吗
    CoderLife
        6
    CoderLife  
    OP
       2019-12-23 13:19:34 +08:00
    @cyannnna 没有开 杯具了

    @luozic redis 都没有对外: ```bind 127.0.0.1```
    @MadHouse kill 了一会又出来了, 且找不到痕迹
    sambawy
        7
    sambawy  
       2019-12-23 13:21:47 +08:00
    crontab -l 看下有没有定时任务
    CoderLife
        8
    CoderLife  
    OP
       2019-12-23 13:22:43 +08:00
    @sambawy 排查了, 没有, 估计有一个守护进程.
    amaranthf
        9
    amaranthf  
       2019-12-23 13:26:13 +08:00
    看一下 pstree ?
    CoderLife
        10
    CoderLife  
    OP
       2019-12-23 13:28:02 +08:00
    systemd─┬─AliYunDun───24*[{AliYunDun}]
    ├─AliYunDunUpdate───3*[{AliYunDunUpdate}]
    ├─2*[agetty]
    ├─aliyun-service───2*[{aliyun-service}]
    ├─atd
    ├─auditd───{auditd}
    ├─chronyd
    ├─crond
    ├─dbus-daemon
    ├─dhclient
    ├─nginx───2*[nginx]
    ├─node─┬─3*[node───9*[{node}]]
    │ └─5*[{node}]
    ├─polkitd───6*[{polkitd}]
    ├─postmaster───14*[postmaster]
    ├─redis-server───2*[{redis-server}]
    ├─rsyslogd───2*[{rsyslogd}]
    ├─sshd─┬─5*[sshd───bash]
    │ └─sshd───bash───pstree
    ├─systemd-journal
    ├─systemd-logind
    ├─systemd-udevd
    └─tuned───4*[{tuned}]

    @amaranthf 看看呢
    amaranthf
        11
    amaranthf  
       2019-12-23 13:32:00 +08:00
    看不出来……不想重装又杀不掉的话,限制一下那个进程的 cpu 占用吧
    CoderLife
        12
    CoderLife  
    OP
       2019-12-23 13:35:29 +08:00
    @amaranthf 嗯, 先观察一下
    mikeguan
        13
    mikeguan  
       2019-12-23 13:37:02 +08:00 via Android
    看进程启动用户是 postgre,估计和 pgsql 有关了
    先通过 PID 一步一步查下具体执行文件吧,可以搜索下有关 pgsql 挖矿,可能使用的手法都是一样的
    CoderLife
        14
    CoderLife  
    OP
       2019-12-23 13:39:38 +08:00
    @mikeguan 已经把 postgres 改为 nologin 了, pid 往上查就是 systemd 了, 痕迹太少了, 且找不到这个执行的文件
    ragnaroks
        15
    ragnaroks  
       2019-12-23 13:41:27 +08:00
    再开一台一样的机器,对比下已运行进程二进制的 hash,替换常见二进制是惯用手法
    mikeguan
        16
    mikeguan  
       2019-12-23 13:42:52 +08:00 via Android
    @CoderLife 不一定需要登录才能执行脚本啊
    CoderLife
        17
    CoderLife  
    OP
       2019-12-23 13:45:08 +08:00
    @ragnaroks 应该是替换了系统进程, 客户的机器, 开一台不好说的, 也不要说这事....:dodge:
    CoderLife
        18
    CoderLife  
    OP
       2019-12-23 13:45:30 +08:00
    @mikeguan 只能这样, 能防点算点了
    beautwill
        19
    beautwill  
       2019-12-23 13:50:16 +08:00
    不是你的程序的问题,是通过阿里云盾调用过来的,很可能是 AK 泄露了,检查下云助手是否存在 api 调用。
    RadishWind
        20
    RadishWind  
       2019-12-23 14:11:25 +08:00
    在 proc 目录能还原出正在运行的可执行文件,然后设置 iptables 和安全组,ban 掉 C&C 服务器的 ip
    lucifer9
        21
    lucifer9  
       2019-12-23 14:48:30 +08:00
    不想查杀不想重装的话
    把挖矿程序要去连接的 IP 给 ban 了就行了吧
    阿里云不是有防火墙
    abccccabc
        22
    abccccabc  
       2019-12-23 14:54:10 +08:00
    如果把 postgres 暂停掉会怎样呢?
    sugars
        23
    sugars  
       2019-12-23 15:01:15 +08:00
    试试在出方向禁用掉挖矿 ip ?
    ESeanZ
        24
    ESeanZ  
       2019-12-23 15:02:04 +08:00
    @luozic +1
    linnil
        25
    linnil  
       2019-12-23 15:10:21 +08:00
    看到告警,我就觉得:还是不用这云服务比较好。。。
    ThirdFlame
        26
    ThirdFlame  
       2019-12-23 15:14:21 +08:00
    定时任务啊
    npc0der
        27
    npc0der  
       2019-12-23 15:49:59 +08:00
    删除中毒用户 其根目录(或者改名) 删除用户
    根据用户 uid 列出所有该用户下进程 然后 kill
    IamUNICODE
        28
    IamUNICODE  
       2019-12-23 15:54:45 +08:00
    怎么感觉最近隔几天就要出个这帖子,阿里云很容易被感染吗,还是你们都在上面安装 redis 而且不设置 auth ?
    a62527776a
        29
    a62527776a  
       2019-12-23 15:56:11 +08:00
    我前天也遇到了 备份了数据库之后重装了。。
    早期配置比较随意 阿里云全端口开放 redis 没设密码 文件夹也放的比较乱

    重新配置之后好多了 也是 redis 没设密码导致的
    yukiloh
        30
    yukiloh  
       2019-12-23 15:58:14 +08:00 via Android
    群里也看到腾讯云被肉了…
    lvzhiqiang
        31
    lvzhiqiang  
       2019-12-23 16:10:27 +08:00
    重装吧,没有那么多精力就别折腾了~~
    laibin6
        32
    laibin6  
       2019-12-24 08:11:32 +08:00 via iPhone
    之前遇到过,文件全部加了 attr,禁止删除。
    文件名称和系统文件名类似,都在 etc 和 usr 目录,检查一下这两个文件夹下面的文件权限,不是 ls -al 哦
    GoRoad
        33
    GoRoad  
       2019-12-24 08:51:02 +08:00
    碰到过这情况,是通过 redis 入侵的,幸好我 redis 是 docker 装的,把那个容器直接干掉就没事了
    CoderLife
        34
    CoderLife  
    OP
       2019-12-24 10:15:49 +08:00
    @lucifer9 *云的报告还是很有用的
    @abccccabc 与进程无关, 是通过 postgres 这个用户启动的
    @sugars 各种禁了
    @linnil 不用云服务器, 有可能你都不知道被挖矿了
    @ThirdFlame 隐藏得很好, 定时任务里没有
    @npc0der 根本没有目录的
    @IamUNICODE 与云没有关系, 是自己引入的
    @a62527776a @lvzhiqiang 重装的代价太夶了, 图片几十个 G
    @yukiloh 最近矿涨价了?
    @laibin6 哪天深入学习一下 redis 怎么入侵
    @GoRoad 下次也用 docker 了
    sinalvee
        35
    sinalvee  
       2019-12-24 10:48:47 +08:00
    之前遇到过,参考了这篇文章
    http://www.lfming.com/2019/06/13/%E4%B8%80%E6%AC%A1%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%AD%E6%8B%9B%E6%8C%96%E7%9F%BF%E7%97%85%E6%AF%92%E8%A7%A3%E5%86%B3%E8%BF%87%E7%A8%8B/

    主要思路就是,根据他定时任务,拿到了执行的代码,相应的改动删掉,可能其他的地方也有,比如 /etc/bashrc,相关代码也删掉
    linnil
        36
    linnil  
       2019-12-24 13:51:38 +08:00
    之前没有仔细看你发出来的东西,只是看到又有中挖矿木马的替你感到可惜又。。。
    其实这种挖矿木马工作方式大同小异,你上面已经提到自己去用心跟了一下 bash,这样可以解决掉 90%这样的木马。
    我之前所说不用这种云服务商提供的服务是个人觉得他们管的太多。
    之前爆的[redis 挖矿]( https://www.v2ex.com/t/537457)你可以参考一下,排查那些死灰复燃的地方,加留心关注应该就行了。
    你这次中了,应该和`postgresql`有关。
    abccccabc
        37
    abccccabc  
       2019-12-24 16:33:06 +08:00
    最后你怎么处理的?????
    CoderLife
        38
    CoderLife  
    OP
       2019-12-24 18:13:55 +08:00
    @abccccabc 处理了, 看 append 哈
    @sinalvee 看了一下有点类似
    @linnil 目前只要阿里云不再报就可以认为解决了, 这玩意要占 cpu, 安全意识不能薄弱
    laibin6
        39
    laibin6  
       2019-12-24 20:54:54 +08:00 via iPhone
    默认端口+弱密码,全网扫
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1241 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 580ms · UTC 18:02 · PVG 02:02 · LAX 11:02 · JFK 14:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.