中国Linux公社论坛's Archiver

huizige 发表于 2012-3-16 00:01

虚拟机中的杯具,提醒调试脚本的朋友避开这个问题

遍历磁盘的脚本,调试时输出结果看看就杯具了,杯具代码如下
for diskdevname in $(blkid /dev/sd* | cut -d ":" -f1); do
        diskmountdir=/media/live_"${diskdevname#/dev/}"
        echo $diskmountdir ------------>$diskdevname
done
在控制台想看一下效果,一个管道符造成字符串注入磁盘分区设备,奇怪的是LINUX的分区还能访问,FAT和NTFS的都挂了。

bash-4.2# blkid
/dev/sr0: LABEL="livecnc" TYPE="iso9660"
/dev/sr1: LABEL="CDLINUX" TYPE="iso9660"
/dev/sda1: UUID="8bc00b9f-246c-424b-ae3e-8796d4ed01d0" TYPE="ext2"
/dev/sda5: UUID="d2f8e73c-6d9a-4c7f-96df-7e8f432d92d3" TYPE="swap"
/dev/sdb5: UUID="d9d0cf0d-33af-44cf-9afe-a5f51aaaccf9" TYPE="ext2"
bash-4.2# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003a8f5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    14329979     7164958+  83  Linux
/dev/sda2        14329980    20964824     3317422+   5  Extended
/dev/sda5        14330043    15374204      522081   83  Linux
/dev/sda6        15374268    20964824     2795278+   7  HPFS/NTFS/exFAT

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d563d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576    b  W95 FAT32
/dev/sdb2         2099200     4194303     1047552    5  Extended
/dev/sdb5         2101248     4194303     1046528   83  Linux

jiangtao9999 发表于 2012-3-16 15:19

:roll:
把手剁了吧……
所以啊,没事别用 root 权限……

huizige 发表于 2012-3-16 23:01

虚拟机中调试,为的就是应付危险的操作,调试搜索ISO的脚本,想尝试在live cd加载好根目录后调用systemd提高装载速度。

页: [1]

Powered by Discuz! Archiver 6.1.0F  © 2001-2007 Comsenz Inc.