Skip to content

Instantly share code, notes, and snippets.

@dufferzafar
Last active August 29, 2015 14:21
Show Gist options
  • Save dufferzafar/93a3d17a7c1313c2a7bf to your computer and use it in GitHub Desktop.
Save dufferzafar/93a3d17a7c1313c2a7bf to your computer and use it in GitHub Desktop.
Cheating Material For Linux Utility Lab
#####################################################################
# The LuL Cheat Code #
# #
# Editor in chief: #
# #
# pSyCh0_c0d3r #
# #
# Individual Authors: #
# #
# asparagus #
# beingcooper #
# chaichuy #
# gre_boy #
# goldinotes #
# #
# Other Complimentary Resources: #
# #
# git clone https://github.com/zishanAhmad/LUL-1 #
# #
# Agar iss file ki wajah se paas huye toh party chaiye saalon! #
# Subah 4:15 pe uthke banayi hai. #
# #
# Lines beginning with # are comments. #
# Remove the # while copying code. #
# #
# man is your friend! #
# #
#####################################################################
#####################################################################
# #
# INDEX #
# #
# Kernel Compilation #
# RTOS #
# Pre-Compiled RTOS #
# System Calls #
# Kernel Module Steps #
# Sample Kernel Modules #
# Bootloader #
# FTP #
# DHCP #
# SMTP #
# Apache #
# DNS #
# RAID #
# #
#####################################################################
# =============================
# Kernel Compile
# - by chaichuy
# =============================
# Download any kernel version from https://www.kernel.org.
# Extract!
tar -xJvf kernel_verson_name
cd linux-version-name
# For menuconfig
sudo apt-get install libncurss5-dev libncursesw5-dev
# Now modify your modules function like disabling your
# keyboard etc SAVE and EXIT. This Step is OPTIONAL.
make menuconfig
# MAKE - ANDHA TIME
make -j 4
make modules
sudo make modules_install
sudo make install
# Reebot machine
sudo reboot
# =============================
# RTOS
# - by pSyCh0_c0d3r
# =============================
# Download a kernel version
# from: www.kernel.org
#
# and its corresponding patch
# from:
# https://www.kernel.org/pub/linux/kernel/projects/rt/
# UnTAR kernel
tar -xzvf linux-3.12.9.tar.gz
cd linux-3.12.9
# Run Patch!
gzip -cd ../patch-3.12.9-rt12.patch.gz | patch -p1
# Rest same as Kernel Compile
sudo make menuconfig
sudo make
sudo make modules
sudo make modules_install
sudo make install
sudo reboot
# More Help
# http://askubuntu.com/a/83066
# =============================
# Pre Compiled RTOS
# - by gre_boy
# =============================
# 1. Add these repositories manually to /etc/apt/sources.list file.
# From command line enter
sudo gedit /etc/apt/sources.list
# And add these two lines at the end of the file
# deb http://ppa.launchpad.net/abogani/realtime/ubuntu precise main
# deb-src http://ppa.launchpad.net/abogani/realtime/ubuntu precise main
# 2. Now run
sudo apt-get update.
# 3. Now you need to install real time os from the internet:
sudo apt-get install linux-realtime
# 4. Reboot your system, the GRUB should show the real-time OS.
# If your grub does not show the RTOS just installed in the list of available
# kernels, then you need to use boot-repair.
# If you have only linux and it does not shows the kernal.
# You need to just edit /etc/default/grub and remove 0 from the
#
# GRUB_HIDDEN_TIMEOUT=0 <- remove O
# ||
# \/
# GRUB_HIDDEN_TIMEOUT=
# Run
sudo grub-update
# and reboot.
# =============================
# System Calls
# - by beingcooper
# =============================
# 1) Create a directory hello in the kernel source directory:
mkdir hello
cd hello
# 2) Create a "hello.c" file in this folder and add the definition
# of the system call to it as given below (you can use any text editor).
gedit hello.c
# Add these contents!
#include <linux/kernel.h>
asmlinkage sys_hello(void)
{
printk("Hello World\n");
return 0;
}
# 3) Create a "Makefile" in the hello folder and add the given line into it.
gedit Makefile
obj-­y :=hello.o
# Makefiles are indented with tab characters!
# This is to ensure that the hello.c file is compiled and included
# in the kernel source code.
# 4) Change back into the linux-3.16 folder and open Makefile
gedit Makefile
# Goto line:
"core-y += kernel/ mm/ fs/ ipc/ security/crypto/block/"
# Change this to:
"kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/"
# This is to tell the compiler that the source files of our
# new system call (sys_hello()) are in present in the hello directory.
# 5) If your system is a 64 bit system you will need to alter
# the syscall_64.tbl file else syscall_32.tbl.
cd arch/x86/syscalls
gedit syscall_64.tbl
# Add the following line in the end of the file :-
545 i386 hello sys_hello
# 545 – It is the number of the system call .
# It should be one plus the number of the last system call..
# This has to be noted down to make the system call in the userspace program.
# 6) cd include/linux/
gedit syscalls.h
# Add the following line to the end of the file but before #endif statement .
asmlinkage long sys_hello(void);
# This defines the prototype of the function in our system call.
# "asmlinkage" is the key word to indicate all the parameters
# are available in the stack
# 7) Now compile the linux source code.
# TO TEST CODE
# Create a "hello.c" program in your home folder and
# type in the In the following code:
#include <linux/kernel.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
int main()
{
long int r = syscall(545);
printf("System call sys_hello returned %ld\n",r);
return 0;
}
# Now compile this program using the following command.
gcc hello.c
# If all goes well you will not have any errors else,
# rectify the errors.
# Now run the program using the following command.
./a.out
# You will see the following line getting printed in the
# terminal if all the steps were followed correctly.
"System call sys_hello returned 0"
# Now to check the message of the kernel you can run the
# following command.
dmesg
# =============================
# Kernel Module Steps
# - by chaichuy
# =============================
# Make a file hello.c with following code
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
# Create a makefile in the same directory with contents
obj-m += hello.o
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
# Run make
make
# hello.ko will be created
sudo insmode hello.ko
# View log
dmesg | tail -n 5
# or
dmesg
# =============================
# Sample Kernel Modules
# - by beingcooper
# =============================
# Module for right triangle test
"
include <linux/module.h> // included for all kernel modules
include <linux/kernel.h> // included for KERN_INFO
include <linux/init.h> // included for __init and __exit macros
include <linux/moduleparam.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("beingcooper");
MODULE_DESCRIPTION("A Simple Kernel Module");
int a=3, b=4, c=5; // default values
module_param(a, int, 0); // command line input for a, b & c
module_param(b, int, 0);
module_param(c, int, 0);
static int __init hello_init(void)
{
if( (c*c) == (a*a) + (b*b))
printk(KERN_INFO "Traingle with sides %d, %d and %d is a Right Angle Traingle\n",a,b,c);
else
printk(KERN_INFO "Traingle with sides %d, %d and %d is NOT Right Angle Traingle\n",a,b,c);
return 0; // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
"
##############################################
# Module for sum of n natural number
"
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/stat.h>
static int sum=0;
static int myint = 20;
#define DRIVER_AUTHOR "oleola"
#define DRIVER_DESC "A sample driver"
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DRIVER_AUTHOR); // Who wrote this module?
MODULE_DESCRIPTION(DRIVER_DESC); // What does this module do?
module_param(myint,int,0);
static int __init hello_init(void)
{
int i;
printk(KERN_INFO "Series of %d natural numbers :",myint);
for(i=1;i<=myint;i++)
{
sum=sum+i;
printk(KERN_INFO " %d ",i);
}
printk(KERN_INFO "Sum is:%d\n\n\n",sum);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_INFO "Goodbye world\n");
}
module_init(hello_init);
module_exit(hello_exit);
"
##############################################
# Module for sum of n number
"
#include<linux/module.h>
#include<linux/moduleparam.h>
#include<linux/kernel.h>
#include<linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("oleola");
static int n=0,sum=0;
static int array[70];
static int arr_argc=0;
module_param(n,int,0);
module_param_array(array,int,&arr_argc,0000);
static int sum_init(void)
{
int i;
printk(KERN_INFO "Series for summation is :");
for(i=0;i<n;i++)
{
sum=sum+array[i];
printk(KERN_INFO " %d ",array[i]);
}
printk(KERN_INFO "Sum of above series is:%d\n\n\n",sum);
return 0;
}
static void sum_exit(void)
{
printk(KERN_INFO "Goodbye World\n");
}
module_init(sum_init);
module_exit(sum_exit);
"
# =============================
# Bootloader
# - by pSyCh0_c0d3r
# =============================
# Run your editor:
gedit boot.asm
# Add these contents
"
[BITS 16] ; 16-bit Real Mode
[ORG 0x7C00] ; BIOS boot origin
JMP main
; Variables
Message db "pSyCh0_c0d3r", 0x0
AnyKey db "Press any key to reboot...", 0x0
;Print characters to the screen
Println:
LODSB ; Load String
OR AL, AL
JZ Complete
MOV AH, 0x0E
INT 0x10 ;BIOS Interrupt 0x10 - Used to print characters
JMP Println ;Loop
Complete:
CALL PrintNwL
;Prints empty new lines like '\n' in C/C++
PrintNwL:
MOV AL, 0 ; null terminator '\0'
STOSB ; store string
;Adds a newline break '\n'
MOV AH, 0x0E
MOV AL, 0x0D
INT 0x10
MOV AL, 0x0A
INT 0x10
RET
;Reboot the Machine
Reboot:
;Sends us to the end of the memory
;Causing reboot
DB 0x0EA
DW 0x0000
DW 0xFFFF
;Gets the pressed key
GetPressedKey:
MOV AH, 0
INT 0x16 ;BIOS Keyboard Service
MOV AH, 0
INT 0x16 ;BIOS Keyboard Service
RET
;Bootloader entry-code
main:
CLI ;Clear interrupts
;Setup stack segments
MOV AX, CS
MOV DS, AX
MOV ES, AX
MOV SS, AX
STI ;Enable interrupts
;Print the first characters
MOV SI, Message
CALL Println
CALL PrintNwL
MOV SI, AnyKey
CALL Println
CALL GetPressedKey
CALL Reboot
TIMES 510 - ($-$$) db 0 ;Fill the rest of the bootloader with zeros
DW 0xAA55 ;Boot signature
"
# Install nasm compiler
sudo apt-get install nasm
# Compile your file
nasm -f bin boot.asm -o boot.img
# Make bootable PD
#
# TODO: How to write IMG to PD?
#
# Use in-built tool:
# Startup Disk Creator and select a Disk Image
#
# Use this tool to write IMG file to PD
# http://unetbootin.sourceforge.net/
# Alternate compile and burn steps
# - by asparagus
nasm boot.asm –f bin –o boot.bin
dd if=boot.bin of=/dev/sdX bs=512 count=1
# Here X Can Be Replaced With Your Partition
# =============================
# FTP
# - by goldinotes
# pSyCh0_c0d3r
# =============================
# Install FTP Server
sudo apt-get install vsftpd
# Open the file /etc/vsftpd.conf
#
# Uncomment the following lines
#
# This file will make a nice pastime
write_enable=YES
listen=YES
# Start the service
sudo service vsftpd start
# Replace localhost by IP 192.67.54.14
ftp localhost
# Enter credentials
# Use the commands
#
# get filename
# put filename
# Prepare for VIVA from
man ftp
# =============================
# DHCP
# - by goldinotes
# pSyCh0_c0d3r
# =============================
# Install DHCP Server
sudo apt-get install isc-dhcp-server
# Open the isc-dhcp-server file: /etc/default/isc-dhcp-server
sudo gedit /etc/default/isc-dhcp-server
# Changes interfaces in the last line to
interfaces = "eth0"
# Or just in case you're going for wifi based
interfaces = "wlan0"
# Open the dhcpd.conf: /etc/dhcp/dhcpd.conf
sudo gedit /etc/dhcp/dhcpd.conf
# Scroll down the file to find configurations:
# Lease time ( default and max lease time ) optional
# Domain name and domain name servers
# The range of IP addresses that you want DHCP server to assign to hosts
# The network address
# The subnet mask
# Sample configurations:
# by goldinotes
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.80 192.168.1.90;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 60;
max-lease-time 60;
}
# by pSyCh0_c0d3r
#
# assign a big range,
# so that any IP your client gets falls into it
subnet 10.42.0.0 netmask 255.255.255.0 {
range 10.42.0.1 10.42.0.200;
option domain-name-servers 10.42.0.1;
option domain-name "sample.org";
option routers 10.42.0.254;
option broadcast-address 10.42.0.255;
default-lease-time 60;
max-lease-time 70;
}
# After making changes to the configuration files, save them
# and start the DHCP server
sudo service isc-dhcp-server start
# You need to assign your machine a Manual IP within your range.
# Connect to the client via ethernet cable.
# Make sure that the network settings are selected to DHCP
# at the client's site.
# FINGERS CROSSED!
# Now type the command ifconfig at terminal at client's site.
# You will notice that the ip assigned to client is in between
# the range we defined for the DHCP server.
# =============================
# SMTP
# - by beingcooper
# pSyCh0_c0d3r
# =============================
# Install the following :
sudo apt-get install postfix mailutils dovecot-common dovecot-pop3d dovecot-imapd libsasl2-2 ca-certificates libsasl2-modules
# Open a terminal and then add user by typing :
adduser newusername
# In a new tab (Ctrl+Shift+T)
su newusername
# In first tab type:
echo "message" | mail -s "subject" newusername@localhost
# In the second tab simply type :
mail
# If it isn't working, maybe try out these!
#
# For me, all this was not required!
sudo apt-get purge postfix mailutils dovecot-common dovecot-pop3d dovecot-imapd
sudo apt-get install postfix mailutils dovecot-common dovecot-pop3d dovecot-imapd
sed -i 's/.*inet_interfaces.*/inet_interfaces = all /' /etc/postfix/main.cf
sed -i 's/.*inet_interfaces = localhost.*/#inet_interfaces = localhost /' /etc/postfix/main.cf
echo -e '\ntransport_maps = hash:/etc/postfix/transport \n' >> /etc/postfix/main.cf
touch /etc/postfix/aliases /etc/postfix/transport
postalias /etc/postfix/aliases
postmap /etc/postfix/transport
postmap hash:/etc/postfix/transport
sed -i 's/.*mail_privileged.*/mail_privileged_group = mail /' /etc/dovecot/conf.d/10-mail.conf
sed -i 's/.*mail_location.*/mail_location = mbox:~\/mail:INBOX=\/var\/mail\/%u /' /etc/dovecot/conf.d/10-mail.conf
sudo service dovecot restart
sudo service postfix restart
# To Send Message To GMAIL
# - by beingcooper
# This method will most likely, NOT WORK.
# Keep reading, as there's another way too.
# Make sure your internet connection allows you to
# send spam to your mail.
# Now simply type :
echo "message" | mail -s "subject" your_email_id
# Now Check your Spam folder in your mail.
# If this works, you are probably the luckiest
# bastard in the world. If not:
# Sending mail to GMAIL
# - by pSyCh0_c0d3r
# Open
sudo vim /etc/postfix/main.cf
# Add these lines
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
# Open
sudo vim /etc/postfix/sasl_passwd
# This is a critical step.
#
# You need to provide your own email address, this will
# become the new sender!
#
# So, for eg: gre_boy will write this line as
#
# [smtp.gmail.com]:587 [email protected]:stanfordhereicome
[smtp.gmail.com]:587 [email protected]:YOURPASSWORD
# Some shit!
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
# Some more shit!
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
# These are troubled times, harry!
sudo /etc/init.d/postfix reload
# Try sending a mail
echo "Mail Body" | mail -s "Mail Subject" [email protected]
# This has to work man. IT JUST HAS TO.
#
# If not, you know where to find me.
#
# :(
# More help can be found at
man mail
# =============================
# Apache
# - by pSyCh0_c0d3r
# =============================
# Install stuff!
sudo apt-get install apache2 php5 libapache2-mod-php5
# Restart Server
sudo /etc/init.d/apache2 restart
# Your web files will now be found in /var/www/html/
# So, place PHP files there, and then visit them in your browser
localhost/php_file_name.php
# https://www.digitalocean.com/community/tutorials/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian-vps
# https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
# =============================
# DNS
# - by gre_boy
# =============================
# Method 1: localhost
# We Need To Change Entries Of /etc/hosts File
127.0.0.1 localhost
127.0.0.1 localhost
10.2.0.30 cit
# Now open the shit in browser
##################################
# Method 2: Bind9
#
# With A Foreign Server Given (We have used Krizna)
sudo apt-get install bind9
gedit /etc/bind/named.conf.options
# Uncomment the following:
forwarders {
8.8.8.8;
8.8.4.4;
};
# Restart the server!
sudo service bind9 restart
# Open
gedit /etc/resolv.conf
# Edit nameserver ip to 127.0.0.1 or your serverIP.
nameserver 127.0.0.1
sudo cp /etc/bind/db.local /etc/bind/db.krizna.com
gedit /etc/bind/db.krizna.com
# The edited version of the file:
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ns.krizna.com. root.ns.krizna.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.krizna.com.
@ IN A 192.168.6.5
@ IN AAAA ::1
ns IN A 192.168.6.5
www IN A 192.168.6.10
# Another fucking thing!
sudo cp /etc/bind/db.127 /etc/bind/db.192
gedit /etc/bind/db.192
# Edited version of the file:
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA ns.krizna.com. root.ns.krizna.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.
5 IN PTR ns.krizna.com.
10 IN PTR www.krizna.com.
# Yet another one!
gedit /etc/bind/named.conf.local
# Edited version of the file:
// Forward zone
zone "krizna.com" {
type master;
file "/etc/bind/db.krizna.com";
};
//reverse zone
zone "6.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192";
};
# Instead of 6.168.192 add the first three octets of your network ip.
sudo service bind9 restart
# Now test using nslookup command.
nslookup www.krizna.com
# Output:
# Server: 127.0.0.1
# Address: 127.0.0.1#53
# Name: www.krizna.com
# Address: 192.168.6.10
nslookup 172.27.6.10
# Output:
# Server: 127.0.0.1
# Address: 127.0.0.1#53
# 10.6.27.172.in-addr.arpa name = www.krizna.com
# Source: http://www.krizna.com/ubuntu/configure-dns-server-ubuntu-14-04/
##################################
# Method 3: DNSMASQ
#
# LAN
# WTF IS THIS THING?
sudo apt-get install dnsmasq
gedit /etc/dnsmasq.conf
# Uncomment the following lines:
domain-needed
bogus-priv
no-resolv
no-poll
server=/example.com/192.168.0.5
server=8.8.8.8
server=208.67.220.220
local=/example.com/
address=/doubleclick.net/127.0.0.1
no-hosts
addn-hosts=/etc/dnsmasq.d/hosts.conf
expand-hosts
domain=example.com
dhcp-range=192.168.0.20,192.168.0.50,72h
dhcp-range=tftp,192.168.0.250,192.168.0.254
hcp-host=mylaptop,192.168.0.199,36h
dhcp-option=option:router,192.168.0.1
dhcp-option=option:ntp-server,192.168.0.5
dhcp-option=19,0 # ip-forwarding off
dhcp-option=44,192.168.0.5 # set netbios-over-TCP/IP aka WINS
dhcp-option=45,192.168.0.5 # netbios datagram distribution server
dhcp-option=46,8 # netbios node type
# 'nother file
gedit /etc/dnsmasq.d/hosts.conf
# Add a list of local machines with static IP addresses
# in the same format as the hosts file
# For exmaple:
192.168.0.8 mail mail.example.com
192.168.0.9 smtp smtp.example.com
192.168.0.120 mythtvbox mythtvbox.example.com
# Instead of the given IP's we need to add the addresses of
# those systems which are connected to the network.
# You can now test using the adresses added in the hosts file.
# Source: http://blogging.dragon.org.uk/howto-setup-dnsmasq-as-dns-dhcp/
# Test out shit!
sudo service dnsmasq start
sudo service dnsmasq stop
sudo service dnsmasq restart
# =============================
# RAID
# =============================
# Maine k_ditya ko bola tha ki RAID kar le
# Woh bola ki dwarka_boys[0] ne usse kaha hai
# ki RAID nahin aane wala.
# These should get you started!
# https://raid.wiki.kernel.org/index.php/RAID_setup
# http://askubuntu.com/questions/505446/how-to-install-ubuntu-14-04-with-raid-1-using-desktop-installer
# https://help.ubuntu.com/community/Installation/SoftwareRAID
# https://feeding.cloud.geek.nz/posts/setting-up-raid-on-existing/
@ameenkhan07
Copy link

Redemption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment