Pages

Monday, 11 May 2015

Crontab and wget

I had the following issue - I had to reduce a pretty big xml file to a small file to be downloaded by a mobile app. What I did was pretty simple. In a crontab on my server I set a job for xml compression:

* * * * * root /get.sh >> /tmp/getsh.out 2>&1

In the script:
wget -O /var/www/html/test.xml "http://<domain/ip>/?xml&param=1param&papmm=2param"
bzip2 -c /var/www/html/test.xml > /var/www/html/test.xml.bz2
rm -f /var/www/html/test.xml

So this downloads the xml, bzip shrinks the size and this can be downloaded.

Saturday, 21 March 2015

phpvirtualbox on FreeBSD

Install these:

pkg install virtualbox-ose
pkg install nginx
pkg install php5-soap
pkg install php5-json
pkg install php5-mysqlpkg install php5-sessionpkg install php5-socketspkg install php5-xmlpkg install php5-xmlrpc
pkg install php5-simplexml
pkg install unzip
pkg install virtualbox-ose

You cannot login directly with root over ssh

You will need to create a user and place that user in the wheel group.
Then login with that user and do a su - to become root.

adduser vbox
mkdir /usr/home/vbox
pw usermod vbox -G wheel

You need to load the vboxdrv kernel module via /boot/loader.conf: vboxdrv_load="YES" You also have to add all users to your vboxusers group in order to use vbox. pw groupmod vboxusers -m vbox
chown vbox:vboxusers /usr/home/vbox
Reboot the machine to load the needed kernel modules. Please add the following line to your /etc/rc.conf: vboxnet_enable="YES"
nginx_enable="YES" devfs_system_ruleset="system" 
php_fpm_enable="YES"
vboxwebsrv_enable="YES" vboxwebsrv_user="vbox"
vboxheadless_enable="YES"
vboxheadless_user="vbox" vboxheadless_machines="vm0" vboxheadless_vm0_name="win7" vboxheadless_vm0_user="vbox"
vboxwebsrv_flags="-P /home/ptijo/vboxwebsrv.pid -F /home/ptijo/vboxwebsrv.log -R 5" USB Support: For USB support your user needs to be in the operator group and needs read and write permissions to the USB device. pw groupmod operator -m vbox Add the following to /etc/devfs.rules (create if it doesn't exist): [system=10] add path 'usb/*' mode 0660 group operator Then restart devfs to load the new rules:
/etc/rc.d/devfs restart




chown -R vbox:vboxusers /usr/local/lib/virtualbox
# /usr/local/etc/rc.d/vboxwebsrv start

/usr/local/www/
/usr/local/etc/nginx/nginx.conf

user www;
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
server_name localhost;

charset utf-8;

location / {
root /usr/local/www/nginx;
index index.php index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
include fastcgi_params;
}
}
}

VBoxManage setproperty websrvauthlibrary null

References:
http://pc-s.org.ua/?p=756
http://www.tumfatig.net/20120412/the-freebsd-hypervisor-using-virtualbox/
http://www.lissyara.su/articles/freebsd/www/phpvirtualbox/
http://blog.secaserver.com/2011/07/freebsd-nginx-php-fastcgi-installation/
http://habrahabr.ru/post/67152/
http://geekstutorials.com/2010/04/error-pam-authentication-error-for-root-when-trying-to-ssh-to-freebsd-server-as-root/

Tuesday, 24 February 2015

FreeNAS and pkg

I made a home NAS for my purposes unfortunately I ran into a problem and here is the solution:

[root@stuff ~]# pkg                                                             
The package management tool is not yet installed on your system.                
The mechanism for doing this is not secure on FreeBSD 9.2. To securely install  
pkg(8), use ports from a portsnap checkout:                                     
  # portsnap fetch extract                                                      
  # make -C /usr/ports/ports-mgmt/pkg install clean                             
Do you still want to fetch and install it now? [y/N]: y                         
Bootstrapping pkg please wait                                                   
_http._tcp.pkg.FreeBSD.org                                                      
pkg: fail to extract pkg-static    

mount -o rw
#pkg

Bootstrapping pkg please wait                                                   
_http._tcp.pkg.FreeBSD.org                                                      
Installing pkg-1.4.12...                                                        
Extracting pkg-1.4.12: 100%                                                     
Message for pkg-1.4.12:                                                         
 If you are upgrading from the old package format, first run:                   
                                                                                
  # pkg2ng                                                                      
pkg: not enough arguments                                                       
Usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>] [-C <conf
iguration file>] [-R <repo config dir>] [-o var=value] [-4|-6] <command> [<args>
]                                                                               
                                                                                
For more information on available commands and options see 'pkg help'. 

Hope this helps someone.

Wednesday, 28 January 2015

Android v7 compatability PopupMenus, PopUp Window,

Here I will compare some of the solution I tried for the following task: 

I had to create a menu that has icons and is not part of ActionBar so I made the following conclusions:

PopupMenu - seems very nice, but unfortunately you can not just simply add icons to it. There were some possibilities in v7 and you will probably find them on the internet, but I would not recommend you using them. If you anyway want to do this you will have to add v7 compatability and this is how you can do this:

Android Manifest
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="20" />

project.properties
android.library.reference.1=../appcompat_v7

Either choose this copy in the libs folder v7 v4 libraries (recomended)
or
<path to ADT bundle>\sdk\extras\android\support\v7\appcompat

Styles:

<resources>

    <style name="app_theme" parent="android:Theme">
        <item name="android:listViewStyle">@style/TransparentListView</item>
        <item name="android:expandableListViewStyle">@style/TransparentExpandableListView</item>
    </style>

    <style name="TransparentListView" parent="@android:style/Widget.ListView">
        <item name="android:cacheColorHint">@android:color/transparent</item>
    </style>

    <style name="TransparentExpandableListView" parent="@android:style/Widget.ExpandableListView">
        <item name="android:cacheColorHint">@android:color/transparent</item>
    </style>


</resources>

Another more reasonable option is PopupWindow - here you will be able to get icons, but of course you should not forget to add scroll to the menu. And this is the closest I got to what I wanted.

However the best solution for my case was this project:
https://github.com/haiwen/NewQuickAction

Have a look at the code, it is pretty simple and organized also it handles different cases.



Wednesday, 19 November 2014

decode@india.com ransomware


If you get something alike:

Attention! Your computer was attacked by virus-encoder.

All your files are encrypted cryptographically strong, without the original key recovery is impossible!
To get the decoder and the original key, you need to to write us at the email decode@india.com with the subject "encryption" stating your id.
Write in the case, do not waste your and our time on empty threats. 

Responses to letters only appropriate people are not adequate ignore.

You probably already know that you are infected with decode@india.com ransomware and you will most probably search all the blogs, install all the tools they are advertising which do not remove anything, because anyway this ransomware as it seems to me self-deletes itself after encryption.


Some antivirus vendors already  detect the ransomware and you can have a look here (5fab6fbdff1a72cd5eafdd27b5ee11a9):


What else can we say about this ransomware, well first about the infection and how it happens. A registry entry that exploits a vulnerability:  

HKEY_CURRENT_USER\CONTROL PANEL\DESKTOP\TILEWALLPAPER = 48
HKEY_CURRENT_USER\CONTROL PANEL\DESKTOP\WALLPAPER = %APPDATA%\bytor.bmp

Here I noticed some different location for the files:

C:\Documents and Settings\<User>\Start Menu\Programs\Startup\Autostart\bytor.bmp
but also:
C:\Users\<User>\AppData\Roaming\bytor.bmp
C:\Documents and Settings\<User>\Start Menu\Programs\Startup\msiexec.exe 
or something like this
C:\Users\<User>\appdata\local\temp\vup.exe
C:\Windows\system32\isobwdev.exe
C:\Windows\SysWOW64\cleen.bat
C:\Users\rado\AppData\Local\Temp\oQ3jKRk.exe

The following files were temporarily written to disk then later removed:
C:\cleen.bat


Anything else we can say is that it pretty much resembles the functions of Cryptolocker, so if you like to restore the files from shadow copies (Shadow Explorer) it is pointless. Read the following I found about Cryptolocker:


In addition to encrypting the files, the malware also executes several commands to make recovery of files even more difficult. The following command is executed to delete the volume's shadow copies, which removes Windows automatic volume backups:

vssadmin.exe Delete Shadows /All /Quiet
The following commands are also executed to disable the Windows Error Recovery screen at startup:
bcdedit /set {default} recoveryenabled No
bcdedit /set {default} bootstatuspolicy ignoreallfailures

The malware also attempts to disable the following services to reduce security, disable Windows updates, and disable error reporting in order to avoid detection:
wscsvc
WinDefend
wuauserv
BITS
ERSvc
WerSvc

What happens if you write to decode@india.com:
Hello. The cost of obtaining a decoder and a unique key is 1 Bitcoin.
_________________________________________________________________________________

Send us an example of an encrypted file, upload the file to sendspace.com and send us the link, we decrypt it and send it,

After payment we will send  decoder and unique password for your id. 
_______________________________________________________________________________

Payment can be made by exchanging e-currency you comfortable in your country on Bitcoin,
In exchange, you must specify our Bitcoin wallet, our Bitcoin Wallet is _____________________  repeat our Bitcoin Wallet is ________________________
After payment email us quoting the number Bitcoin wallet on which the payment was made and your id.

What can be done?
- Make regular backups.
- Patch your windows:
- If you think an e-mail has a strange attach file - don't open it. If it is from someone you know, first verify that indeed this is the case.

Disinfecting (based on the information we have) and if we suppose anything is left at all:

You will need AVZ4 ( Get it from here http://www.z-oleg.com/secur/avz/download.php) and load a custom script (File>Customscripts). Before loading add the user profile (Replace <User> with what you use). This script might or might not work - use at your own risk!

begin
ExecuteAVUpdate;
ShowMessage('AVZ automatically will close all network connections.'+#13#10+'After restarting networks will be up.');
ExecuteFile('net.exe', 'stop tcpip /y', 0, 15000, true);
if not IsWOW64
  then
   begin
    SearchRootkit(true, true);
    SetAVZGuardStatus(true);
   end;
ClearQuarantine;

TerminateProcessByName('C:\Documents and Settings\<User>\Start Menu\Programs\Startup\msiexec.exe');
TerminateProcessByName('C:\Users\<User>\appdata\local\temp\vup.exe');
TerminateProcessByName('C:\Windows\system32\isobwdev.exe');
TerminateProcessByName('C:\Windows\SysWOW64\cleen.bat');
TerminateProcessByName('C:\Users\<User>\AppData\Local\Temp\oQ3jKRk.exe');
QuarantineFile('C:\Documents and Settings\<User>\Start Menu\Programs\Startup\msiexec.exe');
QuarantineFile('C:\Users\<User>\appdata\local\temp\vup.exe', '');
QuarantineFile('C:\Windows\system32\isobwdev.exe' , '' );
QuarantineFile('C:\Windows\SysWOW64\cleen.bat', '');
QuarantineFile('C:\Users\<User>\AppData\Local\Temp\oQ3jKRk.exe' , '');
QuarantineFile('C:\Users\<User>\AppData\Roaming\bytor.bmp', '');
DeleteFile('C:\Documents and Settings\<User>\Start Menu\Programs\Startup\msiexec.exe');
DeleteFile('C:\Users\<User>\appdata\local\temp\vup.exe');
DeleteFile('C:\Windows\system32\isobwdev.exe');
DeleteFile('C:\Windows\SysWOW64\cleen.bat');
DeleteFile('C:\Users\<User>\AppData\Local\Temp\oQ3jKRk.exe');
DeleteFile('C:\Users\<User>\AppData\Roaming\bytor.bmp');
RegKeyParamDel('HKEY_CURRENT_USER','Software\Microsoft\Windows\CurrentVersion\Run','vup'); 
RegKeyParamDel('HKEY_CURRENT_USER','Software\Microsoft\Windows\CurrentVersion\Run','isobwdev'); 
RegKeyParamDel('HKEY_CURRENT_USER','Software\Microsoft\Windows\CurrentVersion\Run','cleen'); 
RegKeyParamDel('HKEY_CURRENT_USER','Software\Microsoft\Windows\CurrentVersion\Run','oQ3jKRk');
RegKeyParamDel('HKEY_CURRENT_USER','Control Panel\Desktop\','bytor');   
BC_ImportAll;
ExecuteSysClean;
BC_Activate;
RebootWindows(false);
end.

After the restart you can collect a sample that you can send:
begin
CreateQurantineArchive(GetAVZDirectory+'sample.zip'); 
end.

References:

Thursday, 6 November 2014

Dell Inspiron 1545 Goes into Sleep mode randomly

I had a case recently where a Dell Inspiron 1545 that went in sleep mode randomly for no apparent reason so I had to isolate the problem:

- I checked the Power settings
- Tested the memmory
- Tested the hard drive

In the end it turned out to be the wristband on our colleagues hand that had a magnet. We also found a spot where if you hold enough the magnet it will put the laptop into sleep. It also seems that this is not an exception for any 1545 dell inspiron. 

References:
http://en.community.dell.com/support-forums/laptop/f/3518/t/19506101

PHP Project - system information on linux

This is a project I wrote a while ago in 2012. The system is written in PHP and C++ and has a login and several sections summary (overall summary), graphs (network graphs), logs search, routes and traffic information, disk usage etc. The C++ part contains a wrapper that collects all logs. The project is intended to be used as  a console for Linux server monitoring. If you find this product interesting or would like to purchase it. Please contact me here and we will discuss it further.

Login
Summary
Graphs

Search

Network Status

Process Tree

Disk Usage

Processes

Routes