Friday, July 25, 2014

How to dump memory on Linux systems

In this blog,  we will look at a ways for memory dumping. This can come in handy when you want construct forensic or hacking around. This is also  a key part of incident handling when you suspect a system has been compromised.

The utilities that will be used are easily obtain or already installed. The old school method was to use the simple diskdupe aka "dd".   http://en.wikipedia.org/wiki/Dd_%28Unix%29

With this method, you will use the linux-device /dev/mem as the input file,  and write the output  to where ever you specify.


note: Just make sure the target has enough space on BIG memory systems. All examples require root permission for reading the /dev/mem  device

A simple dump  example1 using  the unix dd command;



A simple dump  example2 , with the unix dd,  example2 and setting blocksizes



Next we will use the memdump command, this is a simple tool to use. It requires just execution and you can redirect the output to your file of choice.



This is ideal for the users who don't want to mess with the  unix dd. It's just plain out simple & a one-liner command. I could teach my mother how to use this,  and she's not technical by any means with a computer.Now that you have 2 ways for dumping memory.

Now what can we do with these dumps? The dumps can now  be analyze  by memory collection tools or forensic. You can use programs like "strings" to look or trace for user details  within the dumps.

One more useful tool that can come in handy. The utility "gcore" does the same , but by using a proc-id. let's dump my  mysql pid and write out the  memory usage by that pid and the pid = 940 .



You can compare the size of output to the unix top command;


NOTE: VIRT column is your total memory, should be near the file size of the dump we made.  1.024x 327m=  334,848,000


And my last tip;



to be stealth,you can conduct these commands against the remote serer and dump the output locally using ssh great if you don't want to leave any traces.



Example execution on a remote server and saving the output locally using first  memdump and then dd.



and







 Ken Felix
 Freelance Network & Security Engineer
 kfelix -a--t- socpuppets ---d--o--t--- com

   ^      ^
=( *   * )=
      o 
     /  \

Monday, July 21, 2014

FAP28C followup

This is a followup on  the image upgrades within fortinet support site and the earlier identified  FAP28C problem




http://socpuppet.blogspot.com/2014/07/fortiap-was-bricked-by-upgrading-to-52.html

After playing around with this upgrade using  the fortiexplorer application, I figure heck why not try via the WebGUI. I quickly found out the following;

  1. The upgrade is rejected with a "invalid image" via the WebGUI
  2. The image was compared by checksum and matches the md5 hash
  3.  I re-downloaded the image a few times just for the heck of it
  4. a factoryreset made no difference

Here's some screen shots of this activities;

( The  md5 hash  comparison )




( FAP main page  WebGUI )



( the start of the upgrade )


( immediate error )


note:  The above upgrade process was done , both before and after a factory reset with no improvements

So it would seem like the  FortiEplorer is not corrupting file during the upgrade. I have a  email into fortinet support and a post on the support forum.

We will sit back and see what comes up. But using two methods for upgrading,  all ends in a disaster.  I have a few non-FAP28C models at some in-production site and  I'm very hesitate to upgrade these.

My FAP28C is in a demo lab btw, so these problems don't really effect me.




Ken Felix
Freelance Network/Security Engineer
kfelix  -----a----t---- socpuppets ---dot---com

    ^    ^
=( % % )=
      @
      /   \


What time is it ? atime ctime mtime

In  the unix world and with  the  unix find command, you will need to  know how to search for files that are  suspect of being access/readed, modify or created. Knowing the difference of the three time options with the unix find command, can come in handy. These are known as;
  • atime
  • ctime
  • mtime

Take a look at the following find command using "atime" ( access )




The file name ken1 is being  query by the find string to see if it was access within the last 30s. Access can be any thing such as; access via the  vi, file, cat,  head, tail  or  more, etc.... .

You can use a time modifier such as second, minutes or hours. ( s m h ). In  the  next following demo, we are using 1hour,  60minutes or 3600seconds ( all  = 1 hour btw )


note: without a modifier  atime/ctime/mtime uses 1day

Okay now, how about  the - or  + options? This   "-"  simply means within the last time period or with the "+ "  greater than the  specified time period .

Moving on, let's look at ctime.  The ctime is the creation time. We can also use the a time quantifier to look for  creation of files within a specific time or range.


NOTE:  keep in mind a  file creation time is just that, the time it was created. The access time can't be greater than the creation time.


And lastly, the mtime. Is  the time of the file modification. Take these examples;


 (example1)


(example2)



(example3)



Okay in  example 3 you will see that by the  meer appending of data to an "existing" file does not change the "access" time. So by me echoing  data into an exiting file doesn't change the access-time, but by echoing data into an existing file, will change the modification time.

(example4)



The reason & need  for understanding the unix time options, & with the command find is simple;" you need to know the difference with the  inspecting and comparison of files for determining  tampering". This is crictical when you suspect any of the following;

  •    file tampering or modifications
  •    inspection for any compromised file ( rootkits, trojans, etc....)
  •    when conducting forensics or incident handling

Every unix administrator or systems security engineer, should know the difference and understand  these options for the analysis of file creation, access,  or  modifications.


Common clues that you system has been compromised;
  •  utmp/wtmp data is gone
  •  logs are cleared or deleted
  •  the passwd/shadow files are modified or new accounts added or even accounts deleted
  •  crontab entries are changed or delete
  •  the unix utility  lsof shows unknown open file  or unknown services
  •  new daemons are running
  •  process counts are higher than normal
  • the box has been reboot or changed uptime 
  • the file permissions have been changed
  • new files that are hidden
  •  etc....

One last bit of info, it best practice to ensure your unix/linux servers are running a suitable time daemon. It 's also best practice to ensure you know the timezone  that the host is in and to use this TZ information in your collection and reporting.




note: be advise,  as an ethical hacker, I always modify the system time and kill the ntp services to throw off my scent. With out the correct time, it's harder to piecemeal a system breech timeline

The best way to determine your timezone is to use any of the following;

date +%Z

     or

date 



Finally,  for alerting on file changes. It's best to use a tripwire and a rootkit hunter aka rkthunter.

http://en.wikipedia.org/wiki/Open_Source_Tripwire
http://en.wikipedia.org/wiki/Rkhunter


Imho, I think every newly installed systems should have a md5 hash create for all binaries in /usr/bin; /usr/local/bin; etc.....  These hash should be store offline or import into a database. In my experience, one the most common method  a hacker deploys, is to replace known binaries with trojans and to  modify rc.local or linux startup scripts  under /etc/init.d


Ken Felix
Freelance Network/Security Engineer
kfelix  -----a----t---- socpuppets ---dot---com

    ^    ^
=( #  # )=
      @
      /   \

A Cisco 6509 dropping SVI interafces configs

I've ran into a problem where SVI interfaces are being dropped within the cisco IOS config.

Cisco IOS Software, s2t54 Software (s2t54-ADVENTERPRISEK9_NPE-M), Version 15.1(2)SY2, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2014 by Cisco Systems, Inc.
Compiled Wed 26-Feb-14 16:03 by prod_rel_team


This problem has happen dozen + of times. We are still investigating why? And how come  after the initial configuration, we can validate the cfg after initial config?

But later on the nvram startup-config will drop certain  SVIs from the startup-config. So upon a power cycle, you will come up with missing  configurations.



Ken Felix
Freelance Network/Security Engineer
kfelix  -----a----t---- socpuppets ---dot---com

    ^    ^
=( % % )=
      @
      /   \

Saturday, July 19, 2014

FortiAP 28C was bricked by upgrading to 5.2 GA

I update  my fortinet AP28C to software version  5.2GA and bricked it. This was not good !



The  FortiExplorer Application sees the device,  but fails to connects via the cli  access.  Also none of the ethernet ports came active after the upgrade. So obvious the fortigate wif-controller would fail at managing the AP.



{  The moment of fear or relief after submitting to yes  }
 


{ Fortiexplorer  cli access  error  }



{ Downgrading back to 5.0.7 , restored my unit back to being functional }





{ Now after  downgrading to 5.0.7 we are back to normal and the FortiExplorer can access the console }




key points

  • because of  the usb-management only, you have the console emulated by fortiexplorer application
  • you have no other choice,  but to  downgrade to recover
  • Like the 5.2GA firmware on  the  firewall appliance, this newly release code  has major problems for this AP 
  • always backup your configuration b4 any upgrades
  • keep a copy the existing as-is running image,  before any major or minor software upgrades
  • The lack of a console,  does  not give you  too much help or insight & restrict what little diagnostic evidence you can collect
 btw: The hardware date stamp is approx  1year old ( 2013-7 ). This is my 4th  time since June, I've been burned  by a 5.2GA software upgrade all of which required a downgrade to restore device and network connectivity.

I hope we will see better in the future code releases from Fortinet.

                                         



Ken Felix
Freelance Network/Security Engineer
kfelix  -----a----t---- socpuppets ---dot---com

    ^    ^
=( % % )=
      @
      /   \

A howto diagnostic forticloud issues 5.2GA

Fortinet cloud logging is somethings a challenge to debug. But under 5.2GA,  we can use the diag command to test for  the forticloud connections.


1st issues the diag command with application forticloud  to see our options



2nd we will use the level 1 to see our username and device details. I've circled key items that we must take note of.



3rd use the level 3 integer to see your log status for bytes and quotas


Next we will use the diag debug en and miglogd option to validate logs are being sent



lastly, to ensure traffic is being sent to forticloud, we dump on the address or tcp/port that's output from the above.




Key points to remember

  • forticloud is a SMB logging solution
  • requires firewall policies to have logging enabled ( set logtraffic all ) 
  • uses reliable syslog ( tcp )
  • encrypts all log data from  fortigate to forticloud
  • your fortigate must have a interface with public access
  • has quota limits for logging data
  • logging is sent at the completion of the session
  • ensure you can traceroute  if you are experiencing  connectivity issues ( ping is disable )
  • most problems are caused by 1> incorrect user/password  2> upstream devices blocking access
note1: keep in mind the alternative log server ip_address as seen from the output of the diag test application forticl 3 command

note2: you can change the  source address if you have multiple uplink interfaces;

config system fortiguard
  set sourc-ip  x.x.x.x
end
 

 Ken Felix
Freelance Network/Security Engineer
kfelix  -----a----t---- socpuppets ---dot---com

   ^    ^
=( # # )=
     @
     /  \