IntelLabs / kafl.targets

Target components for kAFL/Nyx Fuzzer
Other
26 stars 26 forks source link

Build qemu.windows failed in TASK [Configure IE proxy settings] #42

Closed ycdxsb closed 6 months ago

ycdxsb commented 7 months ago

Hello, When I build qemu.windows, it failed in TASK [Configure IE proxy settings] The version of packer, vagrant and plugins are as below.

root@ubuntu-Legion-Y9000X-IAH7:~/kAFL/kafl/examples/templates/windows# packer version
Packer v1.10.2
root@ubuntu-Legion-Y9000X-IAH7:~/kAFL/kafl/examples/templates/windows# vagrant version
Installed Version: 2.3.6
Latest Version: 2.4.1

To upgrade to the latest version, visit the downloads page and
download and install the latest version of Vagrant from the URL
below:

  https://www.vagrantup.com/downloads.html

If you're curious what changed in the latest release, view the
CHANGELOG below:

  https://github.com/hashicorp/vagrant/blob/v2.4.1/CHANGELOG.md
root@ubuntu-Legion-Y9000X-IAH7:~/kAFL/kafl/examples/templates/windows# vagrant plugin list
vagrant-host-shell (0.0.4, global)
vagrant-libvirt (0.12.2, global)

The failed log show as below.

root@ubuntu-Legion-Y9000X-IAH7:~/kAFL/kafl/examples/templates/windows# make build
packer init windows.pkr.hcl
source /root/kAFL/kafl/examples/templates/windows/../../venv/bin/activate && packer build -var-file win10.pkrvars.hcl windows.pkr.hcl
qemu.windows: output will be in this color.

==> qemu.windows: Retrieving ISO
==> qemu.windows: Trying https://go.microsoft.com/fwlink/p/?LinkID=2208844&clcid=0x409&culture=en-us&country=US
==> qemu.windows: Trying https://go.microsoft.com/fwlink/p/?LinkID=2208844&checksum=sha256%3Aef7312733a9f5d7d51cfa04ac497671995674ca5e1058d5164d6028f0938d668&clcid=0x409&country=US&culture=en-us
==> qemu.windows: https://go.microsoft.com/fwlink/p/?LinkID=2208844&checksum=sha256%3Aef7312733a9f5d7d51cfa04ac497671995674ca5e1058d5164d6028f0938d668&clcid=0x409&country=US&culture=en-us => /root/.cache/packer/d731b3f758e61d53033aa8a67d3d8a3050aa1122.iso
==> qemu.windows: Creating floppy disk...
    qemu.windows: Copying files flatly from floppy_files
    qemu.windows: Copying file: answer_files/10/Autounattend.xml
    qemu.windows: Copying file: scripts/fixnetwork.ps1
    qemu.windows: Copying file: scripts/setup_winrm_public.bat
    qemu.windows: Done copying files from floppy_files
    qemu.windows: Collecting paths from floppy_dirs
    qemu.windows: Resulting paths from floppy_dirs : []
    qemu.windows: Done copying paths from floppy_dirs
    qemu.windows: Copying files from floppy_content
    qemu.windows: Done copying files from floppy_content
==> qemu.windows: Found port for communicator (SSH, WinRM, etc): 4247.
==> qemu.windows: Looking for available port between 5900 and 6000 on 0.0.0.0
==> qemu.windows: Starting VM, booting from CD-ROM
    qemu.windows: The VM will be run headless, without a GUI. If you want to
    qemu.windows: view the screen of the VM, connect via VNC without a password to
    qemu.windows: vnc://0.0.0.0:5976
==> qemu.windows: Overriding default Qemu arguments with qemuargs template option...
==> qemu.windows: Waiting 5s for boot...
==> qemu.windows: Connecting to VM via VNC (0.0.0.0:5976)
==> qemu.windows: Typing the boot commands over VNC...
    qemu.windows: Not using a NetBridge -- skipping StepWaitGuestAddress
==> qemu.windows: Using WinRM communicator to connect: 127.0.0.1
==> qemu.windows: Waiting for WinRM to become available...
    qemu.windows: WinRM connected.
==> qemu.windows: Connected to WinRM!
==> qemu.windows: Provisioning with Ansible...
    qemu.windows: Not using Proxy adapter for Ansible run:
    qemu.windows:   Using WinRM Password from Packer communicator...
==> qemu.windows: Executing Ansible: ansible-playbook -e packer_build_name="windows" -e packer_builder_type=qemu -e packer_http_addr=10.0.2.2:0 -e ansible_winrm_scheme=http -e ansible_proxy=http://127.0.0.1:7897/ -v -e ansible_password=***** -i /tmp/packer-provisioner-ansible3494290844 /root/kAFL/kafl/examples/templates/windows/playbook.yml
    qemu.windows: Using /root/kAFL/kafl/examples/templates/windows/ansible.cfg as config file
    qemu.windows:
    qemu.windows: PLAY [Deploy] ******************************************************************
    qemu.windows:
    qemu.windows: TASK [Gathering Facts] *********************************************************
    qemu.windows: ok: [default]
    qemu.windows:
    qemu.windows: TASK [Configure IE proxy settings to apply to all users] ***********************
    qemu.windows: changed: [default] => changed=true
    qemu.windows:   data_changed: false
    qemu.windows:   data_type_changed: false
    qemu.windows:
    qemu.windows: TASK [Configure IE proxy settings] *********************************************
    qemu.windows: An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 468
    qemu.windows: fatal: [default]: FAILED! => changed=false
    qemu.windows:   msg: 'Unhandled exception while executing module: Exception calling "Set" with "0" argument(s): "InternetSetOptionW(INTERNET_OPTION_PER_CONNECTION_OPTION) failed (The parameter is incorrect, Win32ErrorCode 87)"'
    qemu.windows:
    qemu.windows: PLAY RECAP *********************************************************************
    qemu.windows: default                    : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
    qemu.windows:
==> qemu.windows: Provisioning step had errors: Running the cleanup provisioner, if present...
==> qemu.windows: Deleting output directory...
Build 'qemu.windows' errored after 9 minutes 15 seconds: Error executing Ansible: Non-zero exit status: exit status 2

==> Wait completed after 9 minutes 15 seconds

==> Some builds didn't complete successfully and had errors:
--> qemu.windows: Error executing Ansible: Non-zero exit status: exit status 2

==> Builds finished but no artifacts were created.
make: *** [Makefile:14: build] Error 1
Wenzel commented 7 months ago

Hi @ycdxsb,

thanks for reporting this issue.

So the win_inet_proxy Ansible module failed to set the proxy.

The proxy value is gathered from the environment by windows.pkr.hcl

Maybe try to check if your proxy value has the expected format ? https://docs.ansible.com/ansible/latest/collections/community/windows/win_inet_proxy_module.html#parameter-proxy

If you can share your proxy variable, i could try to get a repro here.

Otherwise, running ansible with maximum verbosity should give you a hint at what's wrong. Edit windows.pkr.hcl#146 and append many -v flags to the ansible command line.

Additionaly i found a similar issue here https://github.com/ansible-collections/community.windows/issues/372

ycdxsb commented 7 months ago

Thanks for your help, I think I have solved this issue. The problem is that the Python version of my Ubuntu 20.04 is Python 3.8, so I am using the old version of kafl.targets. This installs an old Ansible version 6.7.0 rather than 7.1.0 in the latest kafl.targets. The code related to win_inet_proxy in Ansible version 6.7.0 does not handle the exception shown above.

Wenzel commented 6 months ago

Thanks for your feedback on this, I will close the issue !