본문 바로가기

IoT 임베디드

Firmadyne 최종 Qemu 실행문 해석

반응형

[run.sh 파일 내 최종 qemu 실행문]

${QEMU} -m 256 -M ${QEMU_MACHINE} -kernel ${KERNEL}
-drive if=ide,format=raw,file=${IMAGE}
-append "root=${QEMU_ROOTFS} console=ttyS0 nandsim.parts=64,64,64,64,64,64,64,64,64,64 rdinit=/firmadyne/preInit.sh rw debug ignore_loglevel print-fatal-signals=1 user_debug=31 firmadyne.syscall=0"
-nographic
-net nic,vlan=0
-net socket,vlan=0,listen=:2000
-net nic,vlan=0
-net tap,vlan=0,id=net0,ifname=${TAPDEV_0},script=no
-net nic,vlan=2
-net socket,vlan=2,listen=:2002
-net nic,vlan=3
-net socket,vlan=3,listen=:2003 | tee ${WORK_DIR}/qemu.final.serial.log

[run.sh 변수 값 출력]

IMAGE /home/night-ohl/Desktop/Firmadyne/binwalk/firmadyne/scratch//1//image.raw
KERNEL /home/night-ohl/Desktop/Firmadyne/binwalk/firmadyne/binaries//vmlinux.mipseb
QEMU qemu-system-mips
QEMU_MACHINE malta
QEMU_ROOTFS /dev/sda1
WORK_DIR  /home/night-ohl/Desktop/Firmadyne/binwalk/firmadyne/scratch//1/ 

[qemu 각 옵션 해석] 

QEMU MAN PAGE : https://www.mankier.com/1/qemu

 

-m : RAM 용량 명시 (default: 128MiB)

     +) 기본단위는 megabytes인데 용량 뒤에 M 또는 G를 붙여서 메가바이트인지 기가바이트인지 명시 가능.

     +) 짝으로 올 수 있는 옵션은 -slot과 -meaxmem이 있다. (maxmem은 page size 단위로 할당돼야함에 유의)

     ex) qemu-system-x86_64 -m 1G,slots=3,maxmem=4G

 

-hda : 부팅 이미지 

     +) 이미지 파일이 와도 되고 물리적 디바이스가 와도 됨.

    ex) qemu-system-x86_64 -hda image_name.img

    ex) qemu-system-i386 -hda /dev/storage_device

 

-M : 머신

    +) 아키텍처별로 지원 가능한 머신 이름들 다 다름.

    https://wiki.qemu.org/Documentation/Platforms/ARM (arm에서 가능한 machines)

    +) 해당 퀘무에서 쓸 수 있는 머신 종류 보고싶으면 다음과 같은 명령어를 입력하면 됨.

    +) qemu-system-arm -M help

    +) qemu-system-aarch64 -M help

 

-kernel : 사용할 커널 이미지 명시

     +) 커널 이미지로 사용할 bzImage를 명시한다. Linux kernel 또는 multiboot fotmat도 가능.

 

-drive : 드라이브 정의

     +) guest device 뿐만 아니라 블록 드라이버 노드(백엔드)를 생성하는 것도 포함됨.

     +) -blockdev와 -device 옵션을 정의하는 shortcut이라고 봐도 됨.

     +) -blockdev에서 받을수 있는 모든 옵션 사용 가능.

if=interface : drive가 연결된 interface type 정의. (ide, scsi, sd, mtd, floppy pflash, virtio, none 가능)
format : format detecting 하지 않고 사용될 디스크의 형식을 명시, 신뢰할 수 없는 형식 헤더를 해석하지 않도록 format=raw를 명시할 수 있다.
file : drive로 쓰일 disk image 명시. (파일명에 콤마(,)가 들어간다면 두번 적어줘야함. my,file 이라면 my,,file 이렇게)

 

-append : append 뒤에 명시하는 cmdline을 커널의 커맨드라인으로 사용.

 

-nographic : QEMU는 기본적으로 graphical로 컴파일 되어 guest console, QEMU monitor를 출력하는데, 이 옵션을 사용한다면 단순한 command line application이 되며 에뮬레이팅된 serial port가 console로 redirected 됨. 즉 QEMU를 이용하여 serial console 디버깅 할 때 사용. (C-a h를 사용하여 console과 monitor 전환 가능)

 

-nic [tap|bridge|user|l2tpv3|vde|netmap|vhost-user|socket][,...][,mac=macaddr][,model=mn] : 이 옵션은 guest NIC 하드웨어와 host network backend를 한 번에 구성하기 위한 shortcut이다.

host backend 옵션은 -netdev에서 쓰이는 옵션과 동일하다.

guest NIC model은 model=modelname으로 설정 가능.

hardware MAC 주소 설정은 mac=macaddr로 설정 가능.

아래 두 명령어는 완전히 같다. (i386의 default은 e1000이므로 이것도 생략 가능. nic로 명령어를 좀 더 단순하게 할 수 있다.)

qemu-system-i386 -netdev user,id=n1,ipv6=off -device e1000,netdev=n1,mac=52:54:98:76:54:32
qemu-system-i386 -nic user,ipv6=off,model=e1000,mac=52:54:98:76:54:32

 

-net nic[,netdev=nd][,macaddr=mac][,model=type] [,name=name][,addr=addr][,vectors=v]

on-board NIC 설정 혹은 생성한 후 emulated hub 0(default hub) 혹은 netdev nd에 연결하는 Legacy 옵션이다.

PC target의 default NIC는 e1000이다.

mac 주소는 mac 옵션으로 바꿀 수 있다.

addresss는 addr(PCI cards only)로 바꿀 수 있다.

monitor command에 사용할 수 있도록 name을 지정할 수 있다.

-net 옵션이 지정되지 않는다면 single NIC가 만들어진다.

QEMU는 몇가지 다른 NIC 카드들을 emulate 할 수 있다. -net nic,model=help를 통해 가능한 devics list를 보자.

 

-net user|tap|bridge|socket|l2tpv3|vde[,...][,name=name: host network backend 설정 (netdev option과 동일한 옵션 사용) 그리고 emulated hub 0(default hub)에 연결. hub port 이름을 명시하려면 name 옵션을 써라.

 

-netdev tap,id=id[,fd=h][,ifname=name][,script=file][,downscript=dfile][,br=bridge][,helper=helper]

Configure a host TAP network backend with ID id.

Use the network script file to configure it and the network script dfile to deconfigure it. If name is not provided, the OS automatically provides one. The default network configure script is /etc/qemu-ifup and the default network deconfigure script is /etc/qemu-ifdown. Use script=no or downscript=no to disable script execution.

If running QEMU as an unprivileged user, use the network helper helper to configure the TAP interface and attach it to the bridge. The default network helper executable is /path/to/qemu-bridge-helper and the default bridge device is br0.

fd=h can be used to specify the handle of an already opened host TAP interface.

Examples:

#launch a QEMU instance with the default network script qemu-system-i386 linux.img -nic tap

#launch a QEMU instance with two NICs, each one connected
#to a TAP device
qemu-system-i386 linux.img \ 
-netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0 \ 
-netdev tap,id=nd1,ifname=tap1 -device rtl8139,netdev=nd1


#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge br0
qemu-system-i386 linux.img -device virtio-net-pci,netdev=n1 \ 
-netdev tap,id=n1,"helper=/path/to/qemu-bridge-helper"

 

-netdev bridge,id=id[,br=bridge][,helper=helper]

Connect a host TAP network interface to a host bridge device.

Use the network helper helper to configure the TAP interface and attach it to the bridge. The default network helper executable is /path/to/qemu-bridge-helper and the default bridge device is br0.

Examples:

#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge br0
qemu-system-i386 linux.img -netdev bridge,id=n1 -device virtio-net,netdev=n1

#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge qemubr0
qemu-system-i386 linux.img -netdev bridge,br=qemubr0,id=n1 -device virtio-net,netdev=n1

 

-netdev socket,id=id[,fd=h][,listen=[host]:port][,connect=host:port]

This host network backend can be used to connect the guest's network to another QEMU virtual machine using a TCP socket connection. If listen is specified, QEMU waits for incoming connections on port (host is optional). connect is used to connect to another QEMU instance using the listen option. fd=h specifies an already opened TCP socket.

Example:

# launch a first QEMU instance
qemu-system-i386 linux.img \ -device e1000,netdev=n1,mac=52:54:00:12:34:56 \
-netdev socket,id=n1,listen=:1234

# connect the network of this instance to the network of the first instance
qemu-system-i386 linux.img \ -device e1000,netdev=n2,mac=52:54:00:12:34:57 \
-netdev socket,id=n2,connect=127.0.0.1:1234

 

-netdev socket,id=id[,fd=h][,mcast=maddr:port[,localaddr=addr]]

Configure a socket host network backend to share the guest's network traffic with another QEMU virtual machines using a UDP multicast socket, effectively making a bus for every QEMU with same multicast address maddr and port. Notes:

  1. Several QEMU can be running on different hosts and share same bus (assuming correct multicast setup for these hosts).
  2. mcast support is compatible with User Mode Linux (argument ethN=mcast), see <http://user-mode-linux.sf.net>.
  3. Use fd=h to specify an already opened UDP multicast socket.

Example:

# launch one QEMU instance
qemu-system-i386 linux.img \ -device e1000,netdev=n1,mac=52:54:00:12:34:56 \
-netdev socket,id=n1,mcast=230.0.0.1:1234

# launch another QEMU instance on same "bus"
qemu-system-i386 linux.img \
-device e1000,netdev=n2,mac=52:54:00:12:34:57 \
-netdev socket,id=n2,mcast=230.0.0.1:1234

# launch yet another QEMU instance on same "bus"
qemu-system-i386 linux.img \
-device e1000,netdev=n3,mac=52:54:00:12:34:58 \
-netdev socket,id=n3,mcast=230.0.0.1:1234

Example (User Mode Linux compat.):

# launch QEMU instance (note mcast address selected is UML's default)
qemu-system-i386 linux.img \
-device e1000,netdev=n1,mac=52:54:00:12:34:56 \
-netdev socket,id=n1,mcast=239.192.168.1:1102

# launch UML
/path/to/linux ubd0=/path/to/root_fs eth0=mcast

Example (send packets from host's 1.2.3.4):

qemu-system-i386 linux.img \
-device e1000,netdev=n1,mac=52:54:00:12:34:56 \
-netdev socket,id=n1,mcast=239.192.168.1:1102,localaddr=1.2.3.4

 

반응형