Archives par mot-clé : web

Tutoriel Facebook Buck avec React Native

Nous allons détailler la procédure pour développer avec React Native et compiler efficacement avec Buck sous Linux.

Prérequis

  • Node.js en v5.5 de préférence installer avec NVM
  • android studio ou intellij (sous ubuntu, utilisez umake android)
  • android sdk + platform + API 23 et votre environnement bien paramétré, par exemple dans votre .bashrc:
export ANDROID_HOME="/opt/softs/androidSdk"
export PATH="$PATH:/opt/softs/androidSdk/platform-tools"

Installation

React Native

Documentation

npm install -g react-native-cli

watchman

Documentation

git clone https://github.com/facebook/watchman.git
cd watchman
git checkout v4.7.0  # the latest stable release
./autogen.sh
./configure
make
sudo make install

Buck

git clone https://github.com/facebook/buck.git
cd buck
ant
#./bin/buck --help
ln -s ${PWD}/bin/buck ${HOME}/bin/buck

Création du projet

dans un de vos répertoires, par exemple ~/dev

react-native init AwesomeProject 
cd AwesomeProject 
react-native run-android

Si vous avez correctement configurer votre sdk pour android vous devriez voir votre application déployée et executée sur votre émulateur.

Maintenant SUPPRIMER l’application de votre émulateur afin d’éviter les conflits entre les signatures gradle et buck.

ajout et configuration de BUCK

cd android`
keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"
./gradlew :app:copyDownloadableDepsToLibs

la commande gradle rend les dépendances Gradle disponible pour Buck

Lancement

dans un terminal lancez le packager à la racine du projet:

npm start

compilez, installez et lancez avec buck:

cd android
buck install -r android/app

Port Knocking – Sécurisez votre réseau – Tomato firmware

Si vous cherchez à faire du port knocking sur votre routeur asus avec un firmware Tomato, je vous conseil la lecture de ce blog.

Article très bien fait, mais je vais vous le résumé pour avoir un forward d’un port ssh d’une de vos machines internes vers le routeur puis votre box internet.
Pour plus de détails et d’information de débuggage, référez-vous à ce blog.

But

Machine1
Ssh Port 22
|
Routeur Tomato
28322 + Port Knocking
|
WAN

Howto

Dans Administration->Scripts->Firewall

Ajouter

KNOCK_STEP_TIMEOUT_SEC=25
KNOCK_WEB_ADMIN_TIMEOUT_SEC=300
KNOCK_INTERFACE="br0"
KNOCK_PORT1=28350
KNOCK_PORT2=27334
KNOCK_PORT3=29837
KNOCK_HONEY_PORT_SEQ=4049,28051,27024,28026,29074,15076


 
# Load iptables modules
modprobe xt_recent
 
# Knock chains
iptables -t nat -N knock2 2>/dev/null
iptables -t nat -F knock2
iptables -t nat -A knock2 -m recent --name knock1 --remove
iptables -t nat -A knock2 -m recent --name knock2 --set
iptables -t nat -A knock2 -j LOG --log-level info --log-prefix "IN KNOCK2: "
 
iptables -t nat -N knock3 2>/dev/null
iptables -t nat -F knock3
iptables -t nat -A knock3 -m recent --name knock2 --remove
iptables -t nat -A knock3 -m recent --name knock3 --set
iptables -t nat -A knock3 -j LOG --log-level info --log-prefix "IN KNOCK3: "
 
iptables -t nat -N knock_deny 2>/dev/null
iptables -t nat -F knock_deny
iptables -t nat -A knock_deny -m recent --name knock1 --remove
iptables -t nat -A knock_deny -m recent --name knock2 --remove
iptables -t nat -A knock_deny -m recent --name knock3 --remove
iptables -t nat -A knock_deny -j LOG --log-level warn --log-prefix "KNOCK DENIED: "
 
iptables -t nat -N knock_scanned 2>/dev/null
iptables -t nat -F knock_scanned
iptables -t nat -A knock_scanned -m recent --rcheck --name knock1 \
 --seconds $KNOCK_STEP_TIMEOUT_SEC -j knock_deny
iptables -t nat -A knock_scanned -m recent --rcheck --name knock2 \
 --seconds $KNOCK_STEP_TIMEOUT_SEC -j knock_deny
iptables -t nat -A knock_scanned -m recent --rcheck --name knock3 \
 --seconds $KNOCK_STEP_TIMEOUT_SEC -j knock_deny
 
# 1st knock: KNOCK_PORT1
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp --dport $KNOCK_PORT1 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --set --name knock1
 
# 2nd knock: KNOCK_PORT2
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp --dport $KNOCK_PORT2 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --rcheck --name knock1 --seconds $KNOCK_STEP_TIMEOUT_SEC -j knock2
 
# 3rd knock: KNOCK_PORT3
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp --dport $KNOCK_PORT3 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --rcheck --name knock2 --seconds $KNOCK_STEP_TIMEOUT_SEC -j knock3
 
# To stop port-scans from randomly finding the sequence
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp \
 -m multiport --destination-port $KNOCK_HONEY_PORT_SEQ \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN -j knock_scanned

###############################################################################
# Port forwards after knock
 
# forward port 3124 to ssh of 192.168.1.10:22
iptables -A wanin -i $KNOCK_INTERFACE -p tcp --dport 3124 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --rcheck --seconds $KNOCK_STEP_TIMEOUT_SEC --name knock3 \
 -j ACCEPT
 
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp --dport 3124 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --rcheck --seconds $KNOCK_STEP_TIMEOUT_SEC --name knock3 \
 -j DNAT --to-destination 192.168.1.10:22
 
# FTP
iptables -A wanin -i $KNOCK_INTERFACE -p tcp --dport 21 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --update --seconds $KNOCK_WEB_ADMIN_TIMEOUT_SEC --name knock3 \
 -j ACCEPT
 
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp --dport 21 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --update --seconds $KNOCK_WEB_ADMIN_TIMEOUT_SEC --name knock3 \
 -j DNAT --to-destination 192.168.1.10
 
###############################################################################
# Ports open from WAN to this router after knock
 

# SSH on local router (ssh port has been changed to 3123)
iptables -A INPUT -d 192.168.1.1 -p tcp --dport 3123 \
 -j ACCEPT
 
iptables -t nat -A PREROUTING -i $KNOCK_INTERFACE -p tcp --dport 3123 \
 -m state --state NEW --tcp-flags SYN,RST,ACK SYN \
 -m recent --rcheck --seconds $KNOCK_STEP_TIMEOUT_SEC --name knock3 \
 -j DNAT --to-destination 192.168.1.1

Adapter les paramètres suivant à vos besoins.

interface réseau recevant le flux d’ouverture
KNOCK_INTERFACE= »br0″
knock port 1
KNOCK_PORT1=28350
knock port 2
KNOCK_PORT2=27334
knock port 3
KNOCK_PORT3=29837
une séquence permettant de perturber les scanners de ports
KNOCK_HONEY_PORT_SEQ=4049,28051,27024,28026,29074,15076

pour tester:

// test - port fermé
~$ ssh [email protected] -p 3124
ssh: connect to host 192.168.1.1 port 3124: Connection refused

// ouverture par port knocking
~$ ssh [email protected] -p 28350
ssh: connect to host 192.168.1.1 port 28350: Connection refused
~$ ssh [email protected] -p 27334
ssh: connect to host 192.168.1.1 port 27334: Connection refused
~$ ssh [email protected] -p 29837
ssh: connect to host 192.168.1.1 port 29837: Connection refused

~$ ssh [email protected] -p 3124
[email protected]'s password: 
// OK -port ouvert !!
// Ctrl+c + attendre 30s

~$ ssh [email protected] -p 3124
ssh: connect to host 192.168.1.1 port 3124: Connection refused
// port fermé - timeout OK

[EDIT 2016] Actuellement je n’utilise plus le port knocking mais le « Single Packet authentication » car plus sécurisé, un article bientôt.

Liftweb sample bootstrap with sbt-plugins

Project source accessible in github at https://github.com/heralight/lift_basic_runmode

  • Lift 2.5-M3
  • sbt-runMode (development, production)
  • sbt-js
  • sbt-less
  • modernizr
  • jquery 1.8.3
  • conditional runMode snippet
  • Twitter Bootstrap included to illustrate the use of sbt shell tasks

Goal

Optimize build process in development and production by:

  • conditional compilation js and style files depending on mode configuration.
  • concat file or not
  • compress file or not
  • simplify debugging by separating files in development mode.
  • test production output easily
  • Add custom sbt task like bash script and link to actions

Installation

Uses sbt-plugins plugins.

The current version 0.6-M1 does not work properly with jetty v8. To fix this problem, you can use my fork.


In a temp directory git clone git://github.com/heralight/sbt-plugins.git 
cd sbt-plugin
clean-cache publish-local 

Structure

css and less in main/css js, coffeescript, template in main/js

These directories will be filtered and copied to resourceManaged and include in webappResources.

main js and css name : « app »

naming convention

if filename contains (rules in build.sbt)

  • .p. == production
  • .d. == development
  • .a. == add to output directory, will be included in webAppRessources path and war package.(a.p.xxx, a.d.xxx, a.xxx)

e.g.:

  • app.a.d.css => main css file in development and this file will be included to output directory.
  • app.a.p.js => main js file in production and this file will be included to output directory.
  • app-part.less => not parsed if not import in any « a » file.

Usages

start in development:

development:start 

start in production:

production:start 

stop in development:

development:stop 

stop in production:

production:stop 

dst and pst will do a stop and a start.

compile css manually:

xxmode:less 

compile js manually:

xxmode:js 

clean output:

xxmode:clean 
to clean only css xxmode:less::clean
to clean only js xxmode:js::clean 

Alias

already set in .sbtrc

 

    alias dst=;development:stop;development:start
    alias pst=;production:stop;production:start
    alias dsl= ;development:stop;~development:start
    alias psl= ;production:stop;~production:start
    alias dstop=development:stop
    alias dstart=development:start
    alias dc = development:compile
    alias pstop=production:stop
    alias pstart=production:start
    alias pc = production:compile
    alias dclean=development:clean
    alias pclean=production:clean
    alias djclean=development:js::clean
    alias dlclean=development:less::clean

 

Recommendation

make a clean before swapping modes.

For more details on sbt-plugins, refer to sbt-plugins Readme.

To go further, I recommend you mix this project with the lift-mongo.g8 produced by Tim Nelson.