<?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: Writing a join query to extract usernames from sessionID in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490003#M136863</link>
    <description>&lt;P&gt;Thanks again! I decided to do this in a different way by using Linux Audit logs.&lt;BR /&gt;
I'll either update this page or create a new question if I run into problems.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 22:42:35 GMT</pubDate>
    <dc:creator>arsalanj</dc:creator>
    <dc:date>2020-03-10T22:42:35Z</dc:date>
    <item>
      <title>Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489994#M136854</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;I need help writing a query that finds the username of whoever ran a command on A Linux server. &lt;BR /&gt;
For example, if you look at the log below:&lt;BR /&gt;
&amp;lt;86&amp;gt;Mar  5 18:41:44 server1 useradd[2569]: new user: name=test1, UID=1100, GID=5020, home=/home/test1, shell=/bin/bash&lt;/P&gt;

&lt;P&gt;Someone with the session ID=2569 added a new user "test1".&lt;BR /&gt;
If I run another query like this:  "pid=2569 eventtype=ssh_open", I can see to whom that session belongs.&lt;BR /&gt;
&amp;lt;86&amp;gt;Jan 24 18:34:03 test1 sshd[2569]: pam_unix(sshd:session): session opened for user admin by (uid=0)&lt;/P&gt;

&lt;P&gt;I was trying to write a query like this, but I keep hitting the wall :&lt;/P&gt;

&lt;P&gt;|multisearch &lt;BR /&gt;
    [search index="linux_secure" &lt;BR /&gt;
    eventtype=useradd &lt;BR /&gt;
    | stats values(pid) AS pid1] &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[search index="linux_secure" eventtype=ssh_open
| stats values(pid) AS pid2]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;| where pid1=pid2&lt;/P&gt;

&lt;P&gt;The query above is not correct, and it returns errors like subsearch 1 contains a non-streaming command. &lt;/P&gt;

&lt;P&gt;I want to write something that checks for the identical pid and extracts the username from search2 and the action from search 1.&lt;/P&gt;

&lt;P&gt;Any help would be appreciated.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Arsalan&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:32:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489994#M136854</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-09-30T04:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489995#M136855</link>
      <description>&lt;P&gt;UPDATE2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="linux_secure" (eventtype=useradd OR eventtype=ssh_open)
| rex "new user: name=(?&amp;lt;adduser&amp;gt;[^,]+)"
| stats dc(eventtype) as flag values(adduser) as adduser values(admin) as admin by pid
| where flag &amp;gt;1 and isnotnull(adduser)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I see, this query wii display user name who use &lt;EM&gt;useradd&lt;/EM&gt; command and &lt;EM&gt;admin&lt;/EM&gt;.&lt;BR /&gt;
I'm not sure your field extraction, I keep &lt;CODE&gt;rex&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 01:08:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489995#M136855</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-10T01:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489996#M136856</link>
      <description>&lt;P&gt;Thank you @to4kawa,&lt;/P&gt;

&lt;P&gt;But this query will return all the users who also login but &lt;STRONG&gt;did not&lt;/STRONG&gt; run the useradd command.&lt;/P&gt;

&lt;P&gt;I'm only looking to find users who ran that command.&lt;/P&gt;

&lt;P&gt;Some users have logged in to the systems a long time ago, and they are running commands, the only way for me to map them is by using their pid.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 03:15:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489996#M136856</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-03-10T03:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489997#M136857</link>
      <description>&lt;P&gt;This assumes that the one type uses &lt;CODE&gt;user&lt;/CODE&gt; and the other uses &lt;CODE&gt;name&lt;/CODE&gt;; if not, you will have to fix that part; otherwise this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="linux_secure" AND eventtype="useradd"
| eval earliest = _time - (10 * 60)
| map search="search index=\"linux_secure\" AND eventtype=\"ssh_open\" earliest=$earliest$ latest=$_time$ pid=$pid$ | eval name=$name$, addtime=$_time$ | table _time addtime pid name user"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="linux_secure" (eventtype="useradd" OR eventtype="ssh_open")
| stats dc(eventtype) AS eventtype_count values(name) AS name values(user) AS user BY pid
| where eventtype_count &amp;gt;1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 03:48:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489997#M136857</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-10T03:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489998#M136858</link>
      <description>&lt;P&gt;Thanks Again.&lt;BR /&gt;
I did a field extraction before, so we don't need this part: | rex "new user: name=(?[^,]+)"&lt;BR /&gt;
So, with this query now I'm getting the pid and the user that has been added. But I don't get the username of the user who logged in in ssh_open event and ran that command.&lt;/P&gt;

&lt;P&gt;This is what I'm getting:&lt;BR /&gt;
pid         adduser  flag&lt;BR /&gt;
2569      test1        2&lt;/P&gt;

&lt;P&gt;I want to extract the admin field from ssh_open, then we can now to whom that pid belongs.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 18:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489998#M136858</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-03-10T18:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489999#M136859</link>
      <description>&lt;P&gt;Thank you @woodcock for the above queries.&lt;BR /&gt;
Query number two, return pid, eventtype_count, name ( which is the user that has been added), and user (which is also has the same value as name or it's null).&lt;/P&gt;

&lt;P&gt;I really like query number 1, but for some reason, I can't get it to work. &lt;BR /&gt;
first, it complained about the latest time, I added the latest time but then it did not return anything.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 18:49:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/489999#M136859</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-03-10T18:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490000#M136860</link>
      <description>&lt;P&gt;I updated my answer; does it work now?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 19:03:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490000#M136860</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-10T19:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490001#M136861</link>
      <description>&lt;P&gt;Unfortunately no. The search runs without any errors, but it's not returning anything.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 21:09:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490001#M136861</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-03-10T21:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490002#M136862</link>
      <description>&lt;P&gt;@woodcock I wanted to thank you again for helping me with this.&lt;BR /&gt;
I was reviewing the logs and realized that linux_secure logs are not the best option to do this.&lt;BR /&gt;
I will consider doing this by using Linux Audit logs.&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 22:40:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490002#M136862</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-03-10T22:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a join query to extract usernames from sessionID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490003#M136863</link>
      <description>&lt;P&gt;Thanks again! I decided to do this in a different way by using Linux Audit logs.&lt;BR /&gt;
I'll either update this page or create a new question if I run into problems.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 22:42:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Writing-a-join-query-to-extract-usernames-from-sessionID/m-p/490003#M136863</guid>
      <dc:creator>arsalanj</dc:creator>
      <dc:date>2020-03-10T22:42:35Z</dc:date>
    </item>
  </channel>
</rss>

