Sublime 3 Licensed (Sublime 3 Public Beta)

Go to this link and Download your OS Specific Build:

http://www.sublimetext.com/3

Mac OS X

Open Terminal and Type the following:

1. cd /Applications/Sublime\ Text.app/Contents/MacOS/
2. Now Type  “vim Sublime\ Text″
3. Now Change to hex mode in vim by doing this =>  “:$!xxd”
4. Now we will do find and replace ->> “:%s/5BE509C33B020111/5BE509C32B020111/g”

Now open the sublime and enter the below licence key , it should work like a charm.


WINDOWS

For x64: After install, open sublime-text.exe with hex editor. Find and replace “33 42″ with “32 42″. Save and using this license key to register:

—–BEGIN LICENSE—–
Patrick Carey
Unlimited User License
EA7E-18848
4982D83B6313800EBD801600D7E3CC13
F2CD59825E2B4C4A18490C5815DF68D6
A5EFCC8698CFE589E105EA829C5273C0
C5744F0857FAD2169C88620898C3845A
1F4521CFC160EEC7A9B382DE605C2E6D
DE84CD0160666D30AA8A0C5492D90BB2
75DEFB9FD0275389F74A59BB0CA2B4EF
EA91E646C7F2A688276BCF18E971E372
—–END LICENSE—–

You should copy from Begin License till End License.


UBUNTU:

Follow these to register sublime text 3 in ubuntu
1.Install ghex editor.(in terminal,enter “sudo apt-get install ghex”)..without the quotes.
2.In terminal enter “cd /usr/lib/sublime-text″
3.In terminal enter “sudo ghex sublime_text” & enter your password
4.In open ghex window,navigate to Edit>Replace.
5.In the find string section enter 33 42
6.In the replace with section enter 32 42
7.save and exit.

 

Screen Shot 2013-06-28 at 10.05.24 PM

Keep an Eye on SSH Forwarding!

OpenSSH is a wonderful tool box. The main purpose is to establish encrypted connections (SSH means Secure SHell) on a remote UNIX machine and, once authenticated, to spawn a shell to perform remote administration. Running on port 22 (default), the client (ssh) and the server (sshd) exchange encrypted information (what you type and the result of your command). I’ll not review the long list of options available with SSH but let’s focus on a particular feature: tunneling.

By default, sshd (the server) has the flag AllowTcpForwarding turned on (I won’t start a debate here about this default setting). “TCP Forwarding” allows you to encapsulate any other protocol (based on TCP of course) inside an already established SSH connection. It’s very useful to increase the security of any unsecured protocol exchanging data in clear text (example: to check a mailbox via the POP3 or IMAP protocol). TCP Forwarding is also a common way to “hide” your activity on the network. Here is an example:

# ssh -f -N -L 1100:localhost:110 -f user@pop3.company.com
user@pop3.company.com's password: 
# telnet localhost 1100
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Solid POP3 server ready
quit
+OK session ended
Connection closed by foreign host.

If you want to read more about tunnels, check the following tutorial.

But the ssh client has a much more interesting feature: dynamic port forwarding. When you connect to the remote host and specify a”-D ” argument, the remote ssh server acts as a SOCKS proxy! Example:

# ssh -f -N -D 9001 user@server.company.com

Starting from now, all applications compatible with SOCKS proxies can use the proxy running on 127.0.0.1:9999! Here is an example on FireFox:

firefox-proxy

Click to enlarge

Configured like this, your FireFox will send all HTTP traffic though the remote server via the SSH session. The server will connect to the final website and send the HTTP requests. Really nice! But there are some security concerns:

  • The UNIX server will generate a lot of traffic from the Internet. There is a risk of high resources consumption (bandwidth and/or CPU).
  • As connections will originate from the UNIX server itself, the logged IP address on remote services will be the one of the UNIX server. There is a risk in case of abuse (hidden IP address).
  • By default, the SSH daemon permits all protocols to be forwarded. Some users may abuse your security policy by encapsulating unexpected protocols (Instant Messenging is a good example).

Here follows some steps to use the SSH tunnel in a safe way. First of all, if you don’t really need this feature, disable it! In /etc/ssh/sshd_config, set AllowTcpForwarding to off and restart the sshd process.

Logging

By default, the SSH daemon does not log the sessions established via a tunnel. To show them, you need to run the sshd in debug mode (-d). This is not acceptable in an operational environment. Here is a quick patch to log all outgoing sessions initiated by the sshd with a mapping to the UID (UserID). In serverloop.c, patch the function server_request_direct_tcpip() like this:

915,918d914
<  // BEGIN PATCH TunnelLogging
<  uid_t who;
<  // END PATCH
<
925,930c921,922
<  // BEGIN PATCH TunnelLogging
<  // debug("server_request_direct_tcpip: originator %s port %d, target %s port %d",
<  who = getuid();
<    logit("Tunnel: %s:%d -> %s:%d UID(%d)",
<      originator, originator_port, target, target_port, who);
<  // END PATCH
---
>  debug("server_request_direct_tcpip: originator %s port %d, target %s port %d",
>      originator, originator_port, target, target_port);

For each new TCP session, the following line will be sent to Syslog:

Feb 27 08:03:08 honey sshd[9060]: Tunnel: 127.0.0.1:51209 -> 0.channel26.facebook.com:80 UID(2349)

The patch will allow to correlate who connected and from which IP address.

Restricting the allowed ports

By default, sshd allow to forward TCP sessions to any ports. You can restrict them to specific hosts and/or ports via the PermitOpen parameter (available since release 4.4):

PermitOpen host:port
PermitOpen IPv4_addr:port
PermitOpen [IPv6_addr]:port

Another alternative is to use the local firewall – iptables – to restrict connection initiated by the UNIX server.

Restricting the allowed users or groups

Now that hosts and ports are restricted, it can be useful to restrict who can use the port forwarding feature. Back to the sshd_config man page, let’s have a look at the Match keyword:

Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file. The arguments to Match are one or more criteria-pattern pairs. The available criteria are User, Group, Host, and Address. Only a subset of keywords may be used on the lines following a Match keyword. Available keywords are AllowTcpForwarding, Banner, ForceCommand, GatewayPorts, GSSApiAuthentication, KbdInteractiveAuthentication, KerberosAuthentication, PasswordAuthentication, PermitOpen, RhostsRSAAuthentication, RSAAuthentication, X11DisplayOffset, X11Forwarding, and X11UseLocalHost.

Here are some example. First let’s restrict the users who are allowed to forward TCP sessions:

AllowTcpForwarding no
Match User john,andy,ted
AllowTcpForwarding yes

Or better, allow specific ports per user groups:

AllowTcpForwarding no
Match Group admins
AllowTcpForwarding yes
Match User john,andy,ted
AllowTcpForwarding yes
PermitOpen 192.168.0.1:443

With this configuration, administrators will be able to open unrestricted connections, specific users will be able to open an IMAP session to a single server and all remaining users won’t be allowed to create tunnels.

Restricting the server Internet connectivity

Finally, restrict the Internet connectivity of your server! Even if you don’t allow TCP Forwarding, it’s a good idea. A server should never have a full direct Internet connectivity. Close everything and open connectivity depending on the needs (example: download some patches via HTTP(S) from specific servers).

使用 lsyncd 同步本地和远程目录

自动同步本地服务器(或 VPS)上的目录到另一台或多台远程服务器的办法和工具有很多,最简单的办法可能是用 rsync + cron(参考:用 VPS 给博客做镜像),这种办法有个问题就是 rsync 只能在固定时间间隔里被 cron 调用,如果时间间隔设的太短,频繁 rsync 会增加服务器负担;如果时间间隔设的太长,可能数据不能及时同步。今天介绍的 lsyncd 采用了 Linux 内核(2.6.13 及以后)里的 inotify 触发机制,这种机制可以做到只有在需要(变化)的时候才去同步。lsyncd 密切监测本地服务器上的参照目录,当发现目录下有文件或目录变更后,立刻通知远程服务器,并通过 rsync 或 rsync+ssh 方式实现文件同步。lsyncd 默认同步触发条件是每20秒或者每积累到1000次写入事件就触发一次,当然,这个触发条件可以通过配置参数调整。

lsyncd 已经在 Ubuntu 的官方源里,安装很容易:

$ sudo apt-get update
$ sudo apt-get install lsyncd

lsyncd 安装后没有自动生成所需要的配置文件和目录,需要手动创建:

$ sudo mkdir /etc/lsyncd
$ sudo touch /etc/lsyncd/lsyncd.conf.lua

$ sudo mkdir /var/log/lsyncd
$ sudo touch /var/log/lsyncd/lsyncd.{log,status}

配置 lsyncd,注意 source, host, targetdir 部分,依次是本地需要同步到远程的目录(源头),远程机器的 IP,远程目录(目标):

$ sudo vi /etc/lsyncd/lsyncd.conf.lua
settings {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status"
}

sync {
        default.rsyncssh,
        source = "/home/vpsee/local",
        host = "192.168.2.5",
        targetdir = "/remote"
}

配置本地机器和远程机器 root 帐号无密码 ssh 登陆,并在远程机器上(假设 IP 是 192.168.2.5)创建一个 /remote 目录:

$ sudo su
# ssh-keygen -t rsa
# ssh-copy-id root@192.168.2.5

# ssh 192.168.2.5
# mkdir /remote

配置好后就可以在本地机器上启动 lsyncd 服务了,启动服务后本地机器 /home/vpsee/local 下的目录会自动同步到远程机器的 /remote 目录下:

$ sudo service lsyncd restart

除了同步本地目录到远程目录外,lsyncd 还可以轻松做到同步本地目录到本地另一目录,只要修改配置文件就可以了:

$ sudo vi /etc/lsyncd/lsyncd.conf.lua
settings {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status"
}

sync {
	default.rsync,
	source = "/home/vpsee/local",
	target = "/localbackup"
}

$ sudo service lsyncd restart

Linux主机本地信息自动采集工具(渗透测试必备)

1

LinEnum是一个Linux主机本地信息自动提取的shell脚本,它有超过65项安全检查功能,比如潜在的SUID/GUID文件、Sudo/rhost错误配置等。另外这个脚本还可以根据关键字(比如Password)搜索*.conf和*.log文件,这些功能对于渗透测试人员来说,是非常有用的。

主要功能:

 

1.内核和发行版本
2.系统信息:
主机名
3.网络信息:
IP
路由信息
DNS服务器信息
4.用户信息:
当前用户信息
最近登录用户
枚举所有用户,包括uid/gid信息
列举root账号
检查/etc/passwd中的hash
当前用户操作记录 (i.e .bash_history, .nano_history etc.)
5.版本信息:
Sudo
MYSQL
Postgres
Apache

2

下载地址

绕过VMware虚拟机登录认证神器—VMInjector

VMInjector是一个绕过VMware Wordstation/Player上虚拟机登录认证的工具.支持当前大部分主流操作系统。它的原理是直接操作内存的方式来绕过登录认证。所以这种内存补丁的方式是不持久的,虚拟机重启之后会恢复正常的密码验证功能。

利用条件:

 

1, 宿主机需要是windows(有管理员权限)
2, 虚拟化软件是VMware workstation或者player
3, 存在锁定的虚拟机

 

支持的版本:

宿主机支持32位和64位的windows,虚拟机支持win7,xin xp,MAC OS X,ubuntu大部分版本.

在64位win7主机,vmware 7.1.0,32位xp虚拟机测试通过

下载地址

 

测试心得:

github提供的源码中是用python脚本来注入DLL,我用python2.7.5,psutil模块1.1最新版,遍历主机进程的时候存在
权限不够的问题.(貌似是psutil模块问题?).而且测试了多次都是注入失败.后来发现作者博客里演示的时候用的是编译好的exe.这两个exe在
github上也有,只是后来被作者删掉了.不知道为什么.

所以,需要回滚到github上一个版本来获取exe执行文件。

git clone https://github.com/batistam/VMInjector
cd VMInjector
git rebase -i HEAD~2 (在编辑界面删除第2行文字!!!)

目的是撤销最近的一次提交.这样被删掉的exe文件就回来了.

root@bt:~/VMInjector# ls
LICENSE  README  vminjector  vminjector-src
root@bt:~/VMInjector# git rebase -i HEAD~2
Successfully rebased and updated refs/heads/master.
root@bt:~/VMInjector# 
root@bt:~/VMInjector# 
root@bt:~/VMInjector# ls
LICENSE  vminjector            vminjector64-exe.rar
README   vminjector32-exe.rar  vminjector-src

使用方法命令行下执行,选择需要解锁的虚拟机然后选择操作系统版本.然后再虚拟机登录界面直接回车,不需要密码就可以登录了。

 

[转]定时自动备份网站和数据库的脚本

转自:http://www.lovelucy.info/auto-backup-website-shell-script.html

更新:随着时间推移备份文件越来越多,在同一个目录中难以组织管理。1.1版增加按年月创建目录存放备份文件。

1、备份网站

#!/bin/sh
# File:    /home/backup_shell/backup_web.sh
# Author:  lovelucy
# Version: 1.1

# Some vars
BIN_DIR="/usr/bin"
BCK_DIR="/backup"
WEB_DIR="/var/www/html"
DATE=`date +%F`
DATE_YEAR=`date +%Y`
DATE_MONTH=`date +%m`

# Make Dir
if test -d $BCK_DIR/$DATE_YEAR/$DATE_MONTH
then
    echo "directory $BCK_DIR/$DATE_YEAR/$DATE_MONTH exists."
else
    echo "directory $BCK_DIR/$DATE_YEAR/$DATE_MONTH does not exists. make dir..."
    mkdir -p $BCK_DIR/$DATE_YEAR/$DATE_MONTH
fi

# Backup
tar -czf $BCK_DIR/$DATE_YEAR/$DATE_MONTH/web_$DATE.tar.gz  $WEB_DIR

2、备份数据库

#!/bin/sh
# File:    /home/backup_shell/backup_db.sh
# Author:  lovelucy
# Version: 1.1

# Database info
DB_USER="root"
DB_PASS="db_password"
DB_NAME="db_name"

# Some vars
BIN_DIR="/usr/bin"
BCK_DIR="/backup"
DATE=`date +%F`
DATE_YEAR=`date +%Y`
DATE_MONTH=`date +%m`

# Make Dir
if test -d $BCK_DIR/$DATE_YEAR/$DATE_MONTH
then
    echo "directory $BCK_DIR/$DATE_YEAR/$DATE_MONTH exists."
else
    echo "directory $BCK_DIR/$DATE_YEAR/$DATE_MONTH does not exists. make dir..."
    mkdir -p $BCK_DIR/$DATE_YEAR/$DATE_MONTH
fi

# Backup
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS $DB_NAME | gzip > $BCK_DIR/$DATE_YEAR/$DATE_MONTH/${DB_NAME}_dump_$DATE.gz

3、备份网站日志

#!/bin/sh
# File:    /home/backup_shell/backup_log.sh
# Author:  lovelucy
# Version: 1.1

# Some vars
BIN_DIR="/usr/bin"
BCK_DIR="/backup"
LOG_ERROR="/var/log/web-error_log"
LOG_ACCESS="/var/log/web-access_log"
DATE=`date +%F`
DATE_YEAR=`date +%Y`
DATE_MONTH=`date +%m`

# Make Dir
if test -d $BCK_DIR/$DATE_YEAR/$DATE_MONTH
then
    echo "directory $BCK_DIR/$DATE_YEAR/$DATE_MONTH exists."
else
    echo "directory $BCK_DIR/$DATE_YEAR/$DATE_MONTH does not exists. make dir..."
    mkdir -p $BCK_DIR/$DATE_YEAR/$DATE_MONTH
fi

# Backup
tar -czf $BCK_DIR/$DATE_YEAR/$DATE_MONTH/log_$DATE.tar.gz  $LOG_ERROR $LOG_ACCESS

# Clear logs
echo > $LOG_ERROR
echo > $LOG_ACCESS

4、设置cron定时执行

$ crontab -e

此时会启动默认编辑器vim,添加以下内容

# backup log *daily*
59 3 * * * /home/backup_shell/backup_log.sh
# backup database *weekly*
1 4 * * 5 /home/backup_shell/backup_db.sh
# backup web files *monthly*
5 4 1 * * /home/backup_shell/backup_web.sh

保存后,默认会在/var/spool/cron目录下生成一个以当前用户名命名的文件。以上内容意义为:每一行由空格分割为6部分,依次为“分钟”、“小时”、“日”、“月”、“星期”、“要执行的程序”。故上面的设置是

  • 每天3点59分执行backup_log.sh脚本
  • 每个星期5的4点1分执行backup_db.sh脚本
  • 每个月1号的4点5分执行backup_web.sh脚本

备份操作可能消耗大量资源和时间,应该设置在凌晨访问量小、系统负载低的时候运行。如果有独立的服务器存储备份文件,还可以在脚本中增加ftp或者email传送备份文件到远程服务器的功能。

[转]自动备份网站并同步到 Dropbox

转自:http://www.lovelucy.info/backup-website-and-sync-to-dropbox.html

之前写过一篇博客,记录了 定时自动备份网站和数据库 的脚本,不过只是将 VPS 上的数据打包保存在了本机的一个目录下,要知道真正的容灾备份需要至少在 3 个不同的物理节点上都有一份拷贝的。Email 发送备份文件在数据超多的情况下不太实际,而出于成本考虑我不想为了一个 VPS 又购买另一个来用作 FTP。不禁想到 DropBox,它无疑是很好的选择——基于 Amazon S3 的云存储保证了可靠性,免费的容量已经足够用,也不必担心数据被审查。

一、设置 Dropbox

Dropbox 提供了丰富的 API,使得我们不必使用官方庞大的客户端,而用一些简单轻量的脚本即可直接上传文件。

Dropbox-Uploader 就是这样一个第三方的脚本,并且它已经开源在了 Github。我们将此脚本下载到 VPS 中,即可使用。

$ wget https://raw.github.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh
$ chmod +x dropbox_uploader.sh
$ ./dropbox_uploader.sh

运行脚本,根据提示设置自己的 Dropbox 应用 API,然后按照步骤设置,就可以使用其命令上传和下载文件了。

dropbox_app_create

二、同步备份脚本

脚本根据自己的 VPS 配置进行一些修改。

#!/bin/bash
# 一些配置
DROPBOX_DIR=/$(date +%Y-%m-%d) # Dropbox 目录,根目录 / 是你已经创建的 app 目录
MYSQL_USER="root"
MYSQL_PASS="password"
MYSQL_DB=('wordpress' 'project2')
BACK_DATA=/root/backup-data # 备份文件保存在本地的目录
DATA=/var/www # 需要备份的网站文件

# 定义备份文件名
DataBakName=Database_$(date +"%Y-%m-%d").tar.gz
WebBakName=Web_$(date +%Y-%m-%d).tar.gz
OldData=Database_$(date -d -6day +"%Y-%m-%d").tar.gz
OldWeb=Web_$(date -d -6day +"%Y-%m-%d").tar.gz
# Dropbox 里 30 天以上的旧数据可以清除
Old_DROPBOX_DIR=/$(date -d -30day +%Y-%m-%d) 
# 清理本地保存了 6 天的备份
echo -ne "Delete local data of 6 days old..."
rm -rf $BACK_DATA/$OldData $BACK_DATA/$OldWeb
echo -e "Done"

cd $BACK_DATA
# 导出 MySQL 数据库,并压缩
echo -ne "Dump mysql..."
for db in ${MYSQL_DB[@]}; do
    (/usr/bin/mysqldump -u$MYSQL_USER -p$MYSQL_PASS ${db}.sql)
done
tar zcf $BACK_DATA/$DataBakName *.sql
rm -rf $BACK_DATA/*.sql
echo -e "Done"

# 备份网站文件
echo -ne "Backup web files..."
cd $DATA
tar zcf $BACK_DATA/$WebBakName *
echo -e "Done"

cd $BACK_DATA
# 开始上传到 Dropbox
echo -e "Start uploading..."
./dropbox_uploader.sh upload  $BACK_DATA/$DataBakName $DROPBOX_DIR/$DataBakName
./dropbox_uploader.sh upload  $BACK_DATA/$WebBakName $DROPBOX_DIR/$WebBakName

# 清理 Dropbox 里 30 天前的旧数据
./dropbox_uploader.sh delete $Old_DROPBOX_DIR/

echo -e "Thank you! All done."

然后使用 crontab,让此脚本每几天定时自动运行,网站的所有数据就会安全地备份到 Dropbox 了。其他注意事项,可以参考我之前的一篇 定时自动备份网站和数据库

PHP发送UTF-8编码中文邮件发件人和标题乱码

标题乱码

当我们使用下面的PHP语句发送中文电子邮件的时候,会发现邮件的标题是乱码,而邮件正文却是正确的,如何才能使得邮件标题不是乱码呢?

$subject = stripslashes($the_post['Title']);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$message = stripslashes(strip_tags($the_post['Content']));
mail($to, $subject, $message, $headers);

先用函数base64_encode() — 使用 MIME base64 对数据进行编码

标题字符串前加编码类型例如: =?UTF-8?B?

标题字符串后加:?=

例如:

$subject = "=?UTF-8?B?".base64_encode($subject)."?=";

将上面一句添加到代码之中,这样,发送的中文邮件标题就不是乱码了。

 

收件人那行都是乱码

$headers = 'To: "=?utf-8?B?' . base64_encode("测试") . '?="  '. "\r\n";
$headers = 'From: "=?utf-8?B?' . base64_encode("测试") . '?="  '. "\r\n";

像这样,确定取出来的数据为utf-8,然后将数据用base64编码。