sonatype-nexus-community / ahab

ahab is a tool to check for vulnerabilities in your apt, apk, or yum powered operating systems, powered by Sonatype OSS Index.
Apache License 2.0
66 stars 17 forks source link

Detect OS automatically #2

Closed fitzoh closed 4 years ago

fitzoh commented 5 years ago

Thanks for creating an issue! Please fill out this form so we can be sure to have all the information we need, and to minimize back and forth.

cc @bhamail / @DarthHater / @ken-duck

ButterB0wl commented 4 years ago

Would it be possible to point ahab to a docker image and have it resolve both the OS and the query so that its abstracted away from the user?

This works using a shell script but im not sure if its possible to run docker daemon commands in go:

scan_with_os() {
  id="$1"
  if [ "${iq_app}" != '' ]; then
    iq_app_id="${id}-${iq_app}"
  else
    iq_app_id="${id}-scan"
  fi
  echo "iq_app_id: $iq_app_id"

  os="$2"
  pkg="$3"
  query="$4"
  echo "The OS name is ${os} the package manager is ${pkg}"
  packages="${tmp_folder}/${id}-packages.txt"
  docker run -it --rm ${container_name} ${query} > ${packages}
  java -jar ${iq_cli_location} -a ${iq_user_name_password} -i ${iq_app_id} -s ${iq_server_address} ${tmp_folder} --stage ${iq_build_stage}
  rm ${packages}
}

docker run -it --rm $container_name cat /etc/os-release

if docker run -it --rm $container_name cat /etc/os-release | grep -q 'ID=alpine' -wc; then
    scan_with_os "alpine" "Alpine Linux" "apk" "apk -v info"
fi

if docker run -it --rm $container_name cat /etc/os-release | grep -q 'ID=debian' -wc; then
    scan_with_os "debian" "Debian" "apt/dpkg" "dpkg-query -W"
fi

if docker run -it --rm $container_name cat /etc/os-release | grep -q 'ID="rhel"' -wc; then
    scan_with_os "rhel" "Redhat Linux" "yum" "yum list installed"
fi

@DarthHater @zendern

DarthHater commented 4 years ago

In theory I imagine you could have something fire off docker exec -it /bin/bash COMMAND_TO_LIST_PACKAGES > packages.out | ./ahab chase --os OS_IN_QUESTION

Go can run shell commands os.Exec I believe, or something akin to that.

ButterB0wl commented 4 years ago

Ideally, I would like ./ahab chase to resolve the current OS and run the appropriate package query by default

and then ./ahab chase -i <image-name> to pull down the image, resolve the OS as above, and run the appropriate package query so that the user doesn't have to figure out the appropriate OS or package query and its abstracted away from them

Not sure how feasible that is...