Jump to content
pyth0n3

A Sh0rt Line C0de

Recommended Posts

Am creat acest topic cu urm?torul scop:

Fiecare poate aduce cate un block de code care face ceva util in sistem , poate fi rulat direct din shell , poate fi scris in orice fel de limbaj de programare suportat de c?tre sistemele *Nix-Like.

Vreau sa fie ceva interactiv , deci in momentul in care eu prezint o bucata de cod , oricine imi poate face quote cu o alternativa mai usoara sau mai complicata.

Incepem asa:

Afiseaza adresa ip externa folosind libnotify-bin

Requires: wget, libnotify-bin

OS:Linux

 notify-send "Your ip is" "`wget -qO- http://whatismyip.org/`"

Cine are alternative imi face quote si isi propune alternativa , daca nu propune o alta bucata de cod care face altceva si mergem mai departe

Depinde doar de imaginatia voastra, codul poate sa faca orice

Edited by pyth0n3
  • Upvote 1
Link to comment
Share on other sites

Afiseaza tara unde te afli in baza ip-ului pe care il ai folosind libnotify-bin

Requires: wget ,libnotify-bin

OS:Linux

notify-send "Your Location is:" "` wget -qO- [url]http://www.ip-address.org/[/url]  |grep "Country:" | awk '{print $41}' | sed "s/  <img//g"`"

Are un mic bug la vizualizarea unor tari, care il gaseste?

Astept alte bucati de cod

Edited by pyth0n3
Link to comment
Share on other sites

Afiseaza scurt si la obiect modelul procesorului, cat ram total ai si ce uptime ai.

Requires: bash

OS: Linux

echo " Procesor" && cat /proc/cpuinfo | grep "model name"| cut -d ":" -f2 && echo " RAM" && cat /proc/meminfo | grep "MemTotal" | cut -d":" -f2 && echo " Uptime" && uptime | cut -d"u" -f1

Print:

Click me :3

Ar fi bine sa fie puse si printuri cu outputul comenzii, si codul sa fie pus cu Quote, nu cu Code, din cauza ca in acest fel poti vedea tot codul fara sa dai horizontal scroll :3

Edited by adonisslanic
Link to comment
Share on other sites

Cmdline pastebin/editor , creaza un fisier de text , genereaza in automat un link catre textul hostat si il copie in clipboard ,trebuie doar facut paste in browser

Dupa ce vine scris mesajul va trebui digitat EOF , aceasta sintaxa inchide editarea textului.

Requires: xsel,curl,libnotify-bin

OS:Linux

cat <<EOF | curl -F 'sprunge=<-' [url]http://sprunge.us[/url] |  xsel -b -i &&  notify-send "Url copied to clipboard , just paste to browser" 

Note: Pentru syntax highlighting trebuie doar adaugat ?<lang> la sfarsitul url-ului

Light Version, face output la link in terminal

Requires:curl

OS:Linux

cat <<EOF | curl -F 'sprunge=<-' [url]http://sprunge.us[/url] 

Edited by pyth0n3
Link to comment
Share on other sites

Ar fi bine sa fie puse si printuri cu outputul comenzii, si codul sa fie pus cu Quote, nu cu Code, din cauza ca in acest fel poti vedea tot codul fara sa dai horizontal scroll :3

Din pacate daca pui quote la cod in momentul in care vrei sa faci quote la un user codul scris in precedenta intre quote dispare si nu reusesti sa iti dai seama la ce ai facut quote.

Duce in eroare .

System,Release ,Platform ,Machine, Processor,Architecture,Version

Requires: python

OS:Cross platform

python -c "import platform;print'---'*18; print 'System   :', platform.system(); print 'Release  :', platform.release();print 'Platform :', platform.platform();print 'Machine  :', platform.machine();print 'Processor:', platform.processor();print 'Architec :', ' '.join(platform.architecture());print 'Version  :', platform.version() ;print '---'*18"

Edited by pyth0n3
Link to comment
Share on other sites

Simple http server cu python. Se listeaza pe port 8000 si este util cand dorim sa punem ceva disponibil pe web, fara a avea apache sau alt daemon instalat.

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"

Acelasi lucru, insa se listeaza pe port 80

python -m SimpleHTTPServer 80

  • Upvote 1
Link to comment
Share on other sites

Generare de parole sigure din CLI:

tr -dc A-Za-z0-9_ < /dev/urandom | head -c 20 | xargs

openssl rand -base64 12

openssl rand -base64 37 | cut -c1-37

openssl rand -base64 37 | sed -e 's/^\(.\{37\}\).*/\1/g'

openssl rand -base64 37 | awk 'BEGIN{FS=""} {for (i=1;i<=37;i++) printf("%s",$i);} {printf "\n"}'

  • Upvote 1
Link to comment
Share on other sites

Screenshot la consola, cand suntem conectati remote, prin ssh:

vidcontrol -p  < /dev/ttyv0 | scr2png -v > screenshot.png

vidcontrol se gaseste in sistemele BSD , poate fi gasit si in Kfreebsd

O alternativa:

cat /dev/vcs1 > tty1 && less tty1

vcs1=tty1

vcs2=tty2

vcs3=tty3

vcs4=tty4

vcs5=tty5

vcs6=tty6

vcs7=tty7

Si inca una care de fapt merge pe acelasi principiu

sudo setterm -dump 1 && less screen.dump 

Unde 1 este numarul de la primul tty

Edited by pyth0n3
  • Upvote 1
Link to comment
Share on other sites

Red-Hat like custom prompt

Requires:sh or bash

OS:Linux

cd && echo -e 'if [ $(id -u) -eq 0 ];\nthen\n\tPS1="\\[$(tput setaf 1)\\][\\u@\\h:\\w]# \\[$(tput sgr0)\\]"\nelse\n\tPS1="[\\u@\\h:\\w]$ "\nfi' > .newlook && sh -c "if grep -q .newlook .bashrc ; then clear && echo Already done! ; else echo 'source .newlook' >> .bashrc && clear && echo Done ; fi"

piceyk.jpg

Bring me back

cd && >.newlook

@tex Uneori ai nevoie si de history ,iar atata timp cat e pc-ul tau si e si criptat poti sa faci si putina history

Edited by pyth0n3
Link to comment
Share on other sites

@tex Uneori ai nevoie si de history ,iar atata timp cat e pc-ul tau si e si criptat poti sa faci si putina history

// offtopic

Just kidding. Eu am history si de acum 2 ani. Maresc HISTSIZE, HISTFILESIZE si modific HISTTIMEFORMAT pentru a vedea data exacta.

// ontopic

DDoS din CLI cu perl.


perl -e 'use Socket; socket(rtfm, PF_INET, SOCK_DGRAM, 0); for (;;) { send(rtfm, 0, 0, sockaddr_in(80, inet_aton("10.0.0.12"))); }'

Link to comment
Share on other sites

Change default shell to Korn Shell, enable vi-style file completion and

make AIX like shell promt

Note:

To complete a file or directory name with vi set press the ESC key and

then the \ (backward slash) key. (Could also work tab completion in some cases.)

Requires:chsh,ksh

OS:Linux

chsh -s /bin/ksh && echo -e 'if [ -z "$VISUAL" -a -z "$EDITOR" ]; then\n\tset -o vi\nfi\ncd $HOME\nPS1="[`logname`@`hostname -s`]/>"' >  $HOME/.kshrc

Go Bash again

chsh -s /bin/bash

HTML_to_PDF converter

Transform html to pdf

Join created pdf into 1 big pdf file

Must run in the same directory where files are stored

Bug/Error:You may encounter an error when a filename have a space

Example: it will process atest.html but not a test.html

Will save the file to "random_value_big.pdf" in the same directory

Requires:wkhtmltopdf,pdftk

OS:Linux

for f in *.html ; do wkhtmltopdf --ignore-load-errors $f $f.pdf  ; done &&  pdftk *.pdf  cat  output  `date +%s`_big.pdf && clear && echo "Done."

Link to comment
Share on other sites

Show machine, software revision and patch revi-sion information ,determine physical memory

Display instruction set architectures ,displays information about processors.

OS:Unix-Solaris

clear && echo "###" &&  showrev && prtconf | grep -i  Memory && echo "Architecture" `isainfo -bv` && psrinfo -pv && echo "###"

Edited by pyth0n3
Link to comment
Share on other sites

Corporation HTTP Firewall/Proxy bypass

OS:Unix/Linux

Requires: corkscrew ssh client/server

Se insaleaza serverul SSH pe un pc acasa,un server dedicat ,host privat .etc, trebuie configurat sa ruleze pe portul 443

Note: De obicei 443 nu vine blocat de catre un enterprise

Pe pc-ul de la munca se ruleaza urmatoarea linie de cod in cazul in care se foloseste un proxy http care nu necesita login

echo -e "Host NAME\nHostname IP\n\tUser USERNAME\n\tPort PORTNUMBER\nProxyCommand `whence corkscrew` PROXY PORT %h %p" > $HOME/.ssh/test ; clear && cat $HOME/.ssh/test

Pe pc-ul de la munca se ruleaza urmatoarea linie de cod in cazul in care se foloseste un proxy http care necesita login


echo -e "Host NAME\nHostname IP\n\tUser USERNAME\n\tPort PORTNUMBER\nProxyCommand `whence corkscrew` PROXY PORT %h %p $HOME/.ssh/auth_proxy" > $HOME/.ssh/test ; clear && cat $HOME/.ssh/test

Setare user si pass pt proxy


echo "PROXYUSER:PROXYPASS" > $HOME/.ssh/auth_proxy

Unde modificam:

NAME -> Un alias pentru host poate fi oricare nume EX:mylab

IP -> Adresa ip a serverului ssh de acasa EX:myprivate.network.org

USERNAME -> Username pt ssh Ex:root

PORTNUMBER -> Portul pt ssh Recomand 443 (Nu vine blocat de catre Firewall/Proxy)

PROXY -> Adresa de proxy unde vreti sa faceti bypass (adresa de proxy a companiei) Ex:corporation.spy.me

PORT -> Portul unde ruleaza acest proxy Ex:8080

PROXYUSER -> username-ul de la proxy

PROXYPASS -> password-ul de la proxy

Se ruleaza urmatorul comand pentru a crea conexiunea

ssh -D 3232 mylab 

Daca conexiunea are success trebuie doar configurat browserul cu un proxy pe localhost pe portul 3232

Note: Portul poate fi ales oricare

In acest caz datele vor trece printun tunnel criptat si nimeni nu isi va baga nasul

Oricum exista diverse variante pentru a face bypass la un proxy sau firewall, aceasta este una din ele si este destul de simpla.

Astept alternativele voastre cu alte linii de cod pentru asa ceva

Edited by pyth0n3
Link to comment
Share on other sites

OS:Unix/Linux

Shell: Bash

Set vi Command-line Editing mode as default in bash

echo "set -o vi" >> $HOME/.bashrc && source ~/.bashrc

Oupsss! vi is not for me , "I Can't Handle This" please bring me back to emacs-like editing mode

Go back Emacs editing mode like it was before

cd $HOME && sed -i'.bak' '/set -o vi/d' .bashrc && source ~/.bashrc

Edited by pyth0n3
Link to comment
Share on other sites

OS : Linux

Simple FTP back-up. Exemplu folosit : Pidgin (salveaza parola în plaintext + log-urile frumos în HTML).

#!/bin/bash

cd $HOME/.purple/

UDIRX='pwd'
HOST='www.site.ro'
FUSER='ftpuser'
PASSWD='ftppasswd'

tar -cf $USER.tar 'logs/' 'accounts.xml'

ftp -n -v $HOST << EOT
ascii
user $FUSER $PASSWD
prompt
mkdir $USER
cd $USER
mput $USER.tar $UDIRX

bye
EOT

rm -rf $USER.tar

Link to comment
Share on other sites

Personalizare cli (acest exemplu functioneaza doar daca masina voastra suporta si are implementata "functia" TPUT), din

[user@masina director] $ <YADA YADA YADA>

in

[[COLOR=#ff0000]TERM[/COLOR] [COLOR=#ff0000]bash[/COLOR](shell-ul preferat sau activ in momentul real):[COLOR=#696969]~[/COLOR](~ - working directory activ, full path)] $ (drepturile user-ului activ: $ pentru non-root; # pentru root>
adica: [[COLOR=#ff0000]TERM[/COLOR] [COLOR=#ff0000]bash[/COLOR]:[COLOR=#696969]~[/COLOR]] $> <YADA YADA YADA>

echo 'export PS1="[\[$(tput [B]setaf 1[/B])\][B]TERM[/B] [B]\s[/B]\[$(tput sgr 0)\]:\[$(tput [B]setaf 1.1[/B])\][B]\w[/B]\[$(tput [B]sgr 0[/B])\]] [B]\$[/B]> "' >> ~/.bashrc

unde

TERM - terminal prescurtat (puteti pune orice vreti sau sa-l stergeti)
\s - shell-ul activ preferat (folositi chsh a.k.a. `change shell' daca preferati alt shell in afara de bash -- cat /etc/shells pentru a vedea lista de login shell-uri disponibile)
\w - pwd a.k.a. `print working directory' - full path, daca doriti doar directorul in care sunteti activ, folositi W ; exemplu: 1. w - ~\Porn\Alicia Stone\Pedobear made me happy 2011\ unde 2. W: Pedobear made me happy 2011
\$ - drepturile utilizatorului la momentul respectiv, in *NIX: $ - alte drepturi decat cele root; # - drepturi sau utilizatorul, root

setaf 1 - rosu
sgr 0 - reset to normal
setaf 1.1 - pentru gri

[!] Daca la executarea `sudo su' nu vi se schimba "indicatorul de acces" ($ in # si vice-versa) incercati aceasta metoda (la mine a functionat):

Copiati urmatoarele linii de cod in ~/.bashrc (cel pentru user-ul vostru) si /root/.bashrc (cel pentru user-ul root)


if [ $(id -u) -eq 0 ]; then
export PS1="[\[$(tput setaf 1)\]TERM \s\[$(tput sgr 0)\]:\[$(tput setaf 1.1)\]\w\[$(tput sgr 0)\]] #> "
else
export PS1="[\[$(tput setaf 1)\]TERM \s\[$(tput sgr 0)\]:\[$(tput setaf 1.1)\]\w\[$(tput sgr 0)\]] $> "
fi

Aduceti schimbarile de rigoare pentru a modifica dupa placere.

[!] In caz ca sunt probleme cand executati `ls' (nu va arata culorile specifice directoarelor, fisierelor etc.), adaugati alias-ul:

alias ls="ls --color"

sau

alias ls="ls --color -a"

daca doriti sa folositi `list all'; in ~/.bashrc sau ~/.bash_profile, depinde ce utilizati pentru alias-uri

Iar mai simplu:

sed -i '$ialias ls="ls --color"' ~/.bashrc
^ pentru list

sed -i '$ialias ls="ls --color -a"' ~/.bashrc
^ pentru list all

Mai multe la

1] How to: Change / Setup bash custom prompt (PS1)

2] BASH Shell change the color of my shell prompt under Linux or UNIX

3] https://wiki.archlinux.org/index.php/Color_Bash_Prompt

Cand nu vrem sa-l facem pe gdb sa taca mereu la fiecare folosire in legatura cu versiunea lui si licenta folosita, utilizam alias-ul:

sed -i '$ialias gdb="gdb --quiet"' ~/.bashrc

Edited by Flubber
fix indicator acces user
Link to comment
Share on other sites

Umatoarea procedura poate fi folositoare intrun range local de peste 500 de servere spre exemplu pentru a face rlogin in fiecare server fara username si pass .

Note: De preferat vine folosita intro retea care are diverse sisteme operative mai vechi pentru compatibilitate intre ele

de altfel poate fi o problema de securitate.

Configurarea vina facuta pe computerul care va administra celelalte sisteme , in cazul meu spre exemplu

ruleaza un sistem operativ Solaris 11

Os:Unix-Solaris10/11

Requires.Service Management Facility (SMF) (Este inclus de default in sistem incepand cu versiunea 10)

Enable Xserver to listen on TCP port (disabled by default)

svccfg -s svc:/application/x11/x11-server setprop options/tcp_listen=true

Check status

svccfg -s svc:/application/x11/x11-server setprop options/tcp_listen

Enable access control for X server

xhost +

Restart GDM (Will restart X server , changes will take effect )

svcadm restart  gdm

Check if the X server is listening

netstat -naf inet | grep 6000

Edited by pyth0n3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...