Wednesday 2 September 2015

Some Fun

It was this lonely weekend.. I was reading some Linux blogs to add to my Linux skills when was stuck with a though to try out some hack as I saw in some movie/real life (You will know as you start reading ;))

So the company I work for holds a directory listing of employees (U got it where I am heading towards). You can access each employees detail along with their pic doing a search with their id (Active Directory Account).

The first challenge I faced was how to get the id of the people. I found that their id is also their email address so if the id is : abcd   then their email address is  abcd@XYZ.com.

So I could easily get the id of the people if I can somehow download all the email addresses in the organisation. But how to do that..
Doing some search I found that i can install Microsoft xchange management tool on my laptop/windows 7 and get connected to my exchange server. I can then use the exchange shell and cmdlets to connect to my exchange server and download all the email accounts. 


How to install the Exchange management tool:
==================================





How to use the exchange shell to get the email accounts:
===========================================




Once I was able to get the email accounts. I just had to do some data formatting. Couple of Linux tools helped me with this.


virtual-machine:~$ grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" addr.txt > hello.txt


addr.txt is the file I got from the exchange tool with all the email addresses. With the above script I got a hello.txt file which only contained the email addresses.


virtual-machine:~$ more hello.txt | awk -F"@" '{print $1}' > hella.txt

I further modified it to only contain the username (Active Directory id). I also did a filter to remove duplicate entries.

virtual-machine:~$ sort -u hella.txt > final.txt

I have the final file now which contains the user accounts/ids.


I now basically wanted to see if I can download the images/pic for the associated ids. Working with the company portal directory listing I found a common place from where the images are being pulled.

It was something like: 

http://www.xyzcompany.com/dir/abcd/zoom/userid


So my next task was to find a tool which could take the ids as feed and use the above url to download the pics associated with the ids.

Here wget was very useful for me which served the purpose. 

wget -i final.txt



This was some fun...