From 97863da4578eb8fd4b99f32bcf17c41fe7d3d036 Mon Sep 17 00:00:00 2001 From: Matt Ray Date: Thu, 16 Jan 2020 21:56:03 +1100 Subject: [PATCH 1/2] Kali Linux platform detection support Signed-off-by: Matt Ray --- lib/train/platforms/detect/specifications/os.rb | 7 +++++++ test/unit/platforms/os_detect_test.rb | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/train/platforms/detect/specifications/os.rb b/lib/train/platforms/detect/specifications/os.rb index 0c7fc9fe..99def075 100644 --- a/lib/train/platforms/detect/specifications/os.rb +++ b/lib/train/platforms/detect/specifications/os.rb @@ -76,6 +76,13 @@ def self.load true end end + plat.name("kali").title("Kali Linux").in_family("debian") + .detect do + if linux_os_release && linux_os_release["ID"].eql?("kali") + @platform[:release] = linux_os_release["VERSION"] + true + end + end plat.name("raspbian").title("Raspbian Linux").in_family("debian") .detect do if (linux_os_release && linux_os_release["NAME"] =~ /raspbian/i) || \ diff --git a/test/unit/platforms/os_detect_test.rb b/test/unit/platforms/os_detect_test.rb index f33e9f94..56000a6e 100644 --- a/test/unit/platforms/os_detect_test.rb +++ b/test/unit/platforms/os_detect_test.rb @@ -140,6 +140,20 @@ def debian_scan(id, version) end end + describe "kali" do + it "sets the correct family/release for kali" do + os_release = "PRETTY_NAME=\"Kali GNU/Linux Rolling\"\nNAME=\"Kali GNU/Linux\"\nID=kali\nVERSION=\"2019.4\"\nVERSION_ID=\"2019.4\"\nVERSION_CODENAME=\"kali-rolling\"\nID_LIKE=debian\nANSI_COLOR=\"1;31\"\nHOME_URL=\"https://www.kali.org/\"\nSUPPORT_URL=\"https://forums.kali.org/\"\nBUG_REPORT_URL=\"https://bugs.kali.org/\"\n" + files = { + "/etc/os-release" => os_release, + "/etc/debian_version" => "kali-rolling", + } + platform = scan_with_files("linux", files) + _(platform[:name]).must_equal("kali") + _(platform[:family]).must_equal("debian") + _(platform[:release]).must_equal("2019.4") + end + end + describe "raspbian" do it "sets the correct family/release for raspbian " do files = { From 4f36f12a31393203bab621f2fd0639d1a7df2eee Mon Sep 17 00:00:00 2001 From: Matt Ray Date: Mon, 27 Jan 2020 13:59:49 +1100 Subject: [PATCH 2/2] Reduce calls of linux_os_release and replace eql? with == based off review Followup on code review feedback Signed-off-by: Matt Ray --- lib/train/platforms/detect/specifications/os.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/train/platforms/detect/specifications/os.rb b/lib/train/platforms/detect/specifications/os.rb index 99def075..635b8f1b 100644 --- a/lib/train/platforms/detect/specifications/os.rb +++ b/lib/train/platforms/detect/specifications/os.rb @@ -78,8 +78,9 @@ def self.load end plat.name("kali").title("Kali Linux").in_family("debian") .detect do - if linux_os_release && linux_os_release["ID"].eql?("kali") - @platform[:release] = linux_os_release["VERSION"] + l_o_r = linux_os_release + if l_o_r && l_o_r["ID"] == "kali" + @platform[:release] = l_o_r["VERSION"] true end end