Showing posts with label OSX. Show all posts
Showing posts with label OSX. Show all posts

April 25, 2016

Baking ISOs in OSX

Ever needed a freshly baked ISO to be used with your virtualbox? I needed one, for some playing around stuff. There's a bunch of answers on superuser, but I found that the suggested command using hdiutils didn't allow the image to be bootable in a virtualbox.

$ hdiutil makehybrid -iso -joliet -o Documents/tools/dest.iso /Volumes/source

So, all things equal, dd should be your best bet. Since dd is both fast and efficient. To use dd you'll have to check where your (dv|c)d is mounted.

$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh HD            499.2 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           +498.9 GB   disk1
                                 Logical Volume on disk0s2
                                 71E61617-FD0B-4FFA-A432-4FE2737C217D
                                 Unlocked Encrypted
/dev/disk2 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            firefox_cache          +596.7 MB   disk2
/dev/disk4 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:        CD_partition_scheme                        *861.7 MB   disk4
   1:              CD_ROM_Mode_1 Hacking LiveCD          750.3 MB   disk4s0


Looking at the CD entry, you'll want to create a binary copy of the disk4s0 image since this is the packed iso file. The other disk4 is the mounted and unpacked file system.

Before creating a copy you'll need to unmount the disk, so you can use it.

$ sudo diskutil umount /dev/disk4s0

Next, generate an ISO image with dd:

$ sudo dd if=/dev/disk4s0 of=my.iso bs=2048 conv=sync,notrunc

Sudo is needed to access the 'real' disk iso. Once the disk image has been generated, check if it can boot with virtualbox.

If you wish to create a bootable CD using dd, just reverse the command, by using the iso ad if and the drive as of, check this guide if you're in doubt. Remember to chown and chmod the image if you wish others that root can use it.

April 05, 2016

Cronnix, crontab & clamscan

Now that you have that clamscan installed, you should create a scheduled scan of your machine. You can do this by adding a crontab job. Crontab is a way to schedule programs to run on various times. Another chrotab job could be a backup, but that's for a different post.

Cronnix, is a GUI for cron, you can install and use this on OSX using ports. IT makes the interface to cron easier to understand for users that don't like to read man pages. If you're ok with man stick to man cron and man cron.

sudo port install cronnix

Select the Cronnix app, and click it.

Next, select new.
Then insert the command you'd like to run: /opt/local/bin/clamscan -r -i -o.  Select simple and select the timing for your cron job.
Press save, and your crontab job should be stored. To verify the schedule you can open a terminal and run:
crontab -l
0    20    *    *    7    /opt/local/bin/clamscan -r -i -o

The above displays the contents of your crontab file. The short version is that every entry in this file divided by a tab character can be read as this: min | hour | day | month | weekday | user | command.

So, the above crontab entry translates to: every sunday @ 20:00 run clamscan. You can get at thorough explanation of cron here. The crontab file is located in /usr/lib/cron/tabs. You can only see the file and contents as super user.

To get a freshclam file you can either create a freshclam entry in crontab or run freshclam as a deamon using:

sudo freshclam -d -c 2 &

The above command executes freshclam as a deamon and checks for a new file twice a day. See man freshclam for detatil.

March 23, 2016

Installing Gimp & checking md5 sums on OSX

After the resent Transmission BitTorrent RansomWare issue on OSX, its time to step up the security. Remeber to add checks when grapping packages and images from the big bad internet. Here's a check when installing tha' Gimp

Download the dmg file for the gimp, wait until its complete. Then copy the md5hash from the page, and fire up a terminal. Then type:

# test $(md5 ~/Downloads/Gimp-2.8.14p2-Mavericks-Yosemite.dmg | cut -d ' ' -f 4) = 30a4a0851f1da76bd4702bf99aec60b3 && echo "ohhh ya"

If you get the ohhh ya, the hashes match and you can go about your business. Please note, it stille dosen't assure that the mounted archive is RansomWare free, just that it came from the Gimp source on the website you down loaded it from.

Now, that takes care of the md5 sums but what about the sha256 issues? Welle if you didn't know the shasum program will help you here. You should grap a copy of Transmission. If you dare `:O.

Then check the file integrity with:

# test $(shasum -a 256 ~/Downloads/Transmission-2.92.dmg | cut -d ' ' -f 1) = 926a878cac007e591cfcea987048abc0689d77e7729a28255b9ea7b73f22d693 && echo "bingo champ install it"

Again if you get the echo bingo champ install it. The file should be ok to install, but backup just to be sure. If you like you can script it, echo'ing the checksums etc. then you may only have t call en chksum.sh "chksum" file script. That's a small project or check what Ted does.

ClamAV & OSX using MacPorts


ClamAv is a command line virus scanner. It runs on all the major platforms, Windown,Linux, and OSX. You can download the source and install it from there, or you can follow these simple steps   to install it using MacPorts.

To install ClamAv check the ports including clam by listing these:

port search clam

Then to install the files issue:

sudo port install clamav clam-server clamsmtp p5-mail-clamav

Once the ports are installed you'll need to configure ClamAv. The following is an extract from the port installation echo:

To configure clamd and freshclam look for the following files:
    /opt/local/etc/clamd.conf
    /opt/local/etc/freshclam.conf

If these files do not exist you can copy the sample conf files into place:

    sudo cp /opt/local/etc/clamd.conf.sample /opt/local/etc/clamd.conf
    sudo cp /opt/local/etc/freshclam.conf.sample /opt/local/etc/freshclam.conf

Edit /opt/local/etc/clamd.conf to your liking, example:

# Comment out 'Example' near the top if it exists
    #Example
    LogFile /opt/local/var/log/clamav/clamd.log
    PidFile /opt/local/var/run/clamav/clamd.pid
    LocalSocket /opt/local/var/run/clamav/clamd.socket
    TCPSocket 3310
    TCPAddr 127.0.0.1
    Foreground yes

Edit /opt/local/etc/freshclam.conf to your liking, example:

# Comment out 'Example' near the top if it exists
    #Example
    UpdateLogFile /opt/local/var/log/clamav/freshclam.log
    PidFile /opt/local/var/run/clamav/freshclam.pid
    NotifyClamd /opt/local/etc/clamd.conf

The important thing when editing these configuration files, is that the directories for clams and freshclam points to the same directories. I let mine point to:

/opt/local/var/log/clamav/
/opt/local/var/run/clamav/

And, make sure that the TCPSocket and TCPAddr are set, enabling you to use ClamAv from within other programs. After installation you'll need to create an entry in the ports share directory. The reason for this is that  ClamAv runs in this directory and the directory is not created on installation. Create it like this:

sudo mkdir -p /opt/local/share/clamav
sudo chown clamav:clamav /opt/local/share/clamav

Now you're ready to create a fresh clam, issue:

sudo freshclam -v

Current working dir is /opt/local/share/clamav
Max retries == 3
ClamAV update process started at Thu Mar 24 00:01:09 2016
Using IPv6 aware code
Querying current.cvd.clamav.net
TTL: 632
Software version from DNS: 0.99.1
main.cvd version from DNS: 57
main.cvd is up to date (version: 57, sigs: 4218790, f-level: 60, builder: amishhammer)
daily.cvd version from DNS: 21470
daily.cld is up to date (version: 21470, sigs: 83891, f-level: 63, builder: neo)
bytecode.cvd version from DNS: 275
bytecode.cvd is up to date (version: 275, sigs: 45, f-level: 63, builder: amishhammer)


ClamAv will generate a new virus signature file. When it is done, you're ready to scan your box. This is done by:

clamscan -ro ~/

----------- SCAN SUMMARY -----------
Known viruses: 4297361
Engine version: 0.99.1
Scanned directories: 132235
Scanned files: 595659
Infected files: 0
Total errors: 4
Data scanned: 72096.62 MB
Data read: 136687.80 MB (ratio 0.53:1)
Time: 22133.709 sec (368 m 53 s)


It'll take loads of time to finish. As, almost, all other codlin tools --help or man clamscan displays all the options you can pass to the program. Next, you'll need to get ClamAv running automatically. Following the installation instructions, another extract:

Two launchd startup items have been installed.
To load clamd and freshclam do the following:
    sudo launchctl load -w /Library/LaunchDaemons/org.macports.clamd.plist
    sudo launchctl load -w /Library/LaunchDaemons/org.macports.freshclam.plist

To unload clamd and freshclam do the following:
    sudo launchctl unload -w /Library/LaunchDaemons/org.macports.clamd.plist
    sudo launchctl unload -w /Library/LaunchDaemons/org.macports.freshclam.plist

Issue both of the commands that loads the deamons, then check that the clamd is running.

ps -aef | grep clamd 

The result should look somewhat like this:

0 25965     1   0  4:52PM ??         0:07.78 /opt/local/sbin/clamd

If your are using Thunderbird and Firefox you can use ClamAv to scan your downloads and your mails. Install the firefox add-on Fireclam, and the Thunderbird add-on clamdrip LIN.

The clam drip LIN extension if meant for Linux only, but it's all runnable using the port version of ClamAv. simply press the: Download for Linux anyway link anyhu!


And import the add on in Thunderbird. Ignore the *beware* message, if you do not trust me, check the contents of the plugin file, using unzip to extract it and inspect the code. It, doesn't look malicious to me.

Next, go to the Thunderbird add on, and select the clam drib preferences. Configure it to listen to the clamd available on localhost:3310.


Now, all you have to do to verify that ClamAv is running, is to check your mail.


The ClamAv status is shown in the green blop above. The information is also shown in the preview pane in Thunderbird.