<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem in parsing Powershell commands in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687649#M234525</link>
    <description>&lt;P&gt;What is your full current search?&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2024 17:39:14 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2024-05-15T17:39:14Z</dc:date>
    <item>
      <title>Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687498#M234470</link>
      <description>&lt;P&gt;Hello Community!&lt;BR /&gt;I am trying to set up a search to monitor Powershell commands from Windows hosts; specifically, I am starting from:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;an index with the full messages related to PS commands, contained in a field named "&lt;EM&gt;Message&lt;/EM&gt;"&lt;UL&gt;&lt;LI&gt;(related, for example, to event codes 4101, 800, etc...)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;a .csv file, with the list of commands I would like to monitored, contained in a column named "&lt;EM&gt;PS_command&lt;/EM&gt;".&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;From these premises, I have already constructed a search that leverages on &lt;EM&gt;inputlookup&lt;/EM&gt; to search the strings from the &lt;EM&gt;PS-monitored.csv&lt;/EM&gt; file to the index field &lt;EM&gt;Message&lt;/EM&gt;, outputting the result in a table, as the following (adding also details from the index: &lt;EM&gt;_time&lt;/EM&gt;, &lt;EM&gt;host&lt;/EM&gt; and &lt;EM&gt;EventCode&lt;/EM&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="wineventlog"

| search ( [|inputlookup PS-monitored.csv | eval Message= "*"  + PS_command + "*" | fields Message] )

| table _time host EventCode Message&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This, despite not being the most elegant solution (with the addition of wildcard characters *), is currently working, however I would also like to include the original search field (PS_command column from &lt;EM&gt;PS-monitored.csv&lt;/EM&gt;) to the final table.&lt;/P&gt;&lt;P&gt;I tried to experiment a bit with &lt;EM&gt;lookup&lt;/EM&gt; command, and with &lt;EM&gt;join&lt;/EM&gt; options, without success; does anyone have some suggestions?&lt;/P&gt;&lt;P&gt;Finally, I would like avoid using heavy commands, such as join, if at all possible.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 14:42:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687498#M234470</guid>
      <dc:creator>valleyman</dc:creator>
      <dc:date>2024-05-14T14:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687510#M234476</link>
      <description>&lt;P&gt;If you include the wildcards in your lookup matching field and define the lookup to use WILDCARD matching, you may be able to lookup a field in the lookup when there is a wildcard match. Please share some anonymised events and contents of your lookup so we can see the sorts of things you are trying to match.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 15:48:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687510#M234476</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-05-14T15:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687574#M234509</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="wineventlog"

| search ( [|inputlookup PS-monitored.csv | eval Message= "*"  + PS_command + "*" | fields Message] )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This makes my teeth itch &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But seriously - doing initial search and then piping to another search is... well, simply not elegant. Splunk will optimize it out anyway and treat as it would a single search command so you could just write it as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="wineventlog" [|inputlookup PS-monitored.csv | eval Message= "*"  + PS_command + "*" | fields Message] &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that's less important.&lt;/P&gt;&lt;P&gt;More important thing is that you're creating a search with a &lt;EM&gt;Message=*something&lt;/EM&gt; conditions. They will be very, very inefficient since Splunk has to parse every single event to find your matching ones.&lt;/P&gt;&lt;P&gt;Assuming your commands are "whole commands" meaning that if your command is "cmd", you're looking for strings like "whatever cmd whatever" and not "whatevercmd whatever" (notice the space difference), you can limit your search with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="wineventlog" [ | inputlookup PS-monitored.csv | eval search=PS_command | fields search | format ] [ | inputlookup PS-monitored.csv | eval Message= "*"  + PS_command + "*" | fields Message] &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could also try to combine those two subsearches into one.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 07:22:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687574#M234509</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-05-15T07:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687600#M234514</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;Thanks for the extensive and very useful feedback!&lt;/P&gt;&lt;P&gt;I have had chance to look at my search again, and with the correction suggested, I am now able to highlight correctly the strings I am interested in the Message field of the index, as the following example&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PS_command_search.jpg" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/30821i75F2EBAC72FC287C/image-size/large?v=v2&amp;amp;px=999" role="button" title="PS_command_search.jpg" alt="PS_command_search.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am perhaps missing one final step, that is to add the &lt;EM&gt;search&lt;/EM&gt; field from the following sub-search in the final table, as I understood the format command should add to my query.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ | inputlookup PS-monitored.csv | eval search=PS_command | fields search | format ]&lt;/LI-CODE&gt;&lt;P&gt;I tried to look for a newly created field "search", or any new created ones, but couldn't find anything...am I missing something obvious?&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 10:26:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687600#M234514</guid>
      <dc:creator>valleyman</dc:creator>
      <dc:date>2024-05-15T10:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687614#M234516</link>
      <description>&lt;P&gt;search, and query are special field names which are removed from the subsearch results i.e. if the subsearch returned&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;( ( search="value1" ) OR ( search="value2" ) )&lt;/LI-CODE&gt;&lt;P&gt;it would be added to the main search as&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;( ( "value1" ) OR ( "value2" ) )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 15 May 2024 12:38:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687614#M234516</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-05-15T12:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687646#M234523</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I think I'm not that far, unfortunately I still cannot figure out how to extract field PS_command from the inputlookup, and passing it into the main search, and eventually how to map it to the Message from the index.&lt;/P&gt;&lt;P&gt;Could you please try to built a little more on the answers?&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 17:01:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687646#M234523</guid>
      <dc:creator>valleyman</dc:creator>
      <dc:date>2024-05-15T17:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in parsing Powershell commands</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687649#M234525</link>
      <description>&lt;P&gt;What is your full current search?&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 17:39:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problem-in-parsing-Powershell-commands/m-p/687649#M234525</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-05-15T17:39:14Z</dc:date>
    </item>
  </channel>
</rss>

