Ads

New Domain

Blog has been moved to new domain: www.it-googled.com Enjoy!

Wednesday 31 August 2011

Unix secondary groups - quick reference

Adding user to new/existing group:
usermod -G group user - adds user to group/multiple groups
usermod -G sales testuser - example
Append user to existing group:
usermod -a -G group user - appends user to group/multiple groups
Link to man usermod http://linux.die.net/man/8/usermod



Removing user from a group:
gpasswd (administer /etc/group)
gpasswd -d user group - removes user from group
usermod -G group user - removes all the other groups apart from specified.
link to man gpasswd http://man.he.net/man1/gpasswd

Tuesday 23 August 2011

Revised Security Auditing

Security Auditing


Security auditing is not very appreciated process within any organization due to the fact that someone external is going to check already hired individuals and their skills. It may be a bit difficult to explain why security is so important and why certain mechanisms should be implemented especially for non-technical management. On the other hand some businesses can appreciate the benefits from security auditing for in result many weaknesses are identified and countered or advise on better software or hardware is given to save that organization’s money.

The mechanism for security audit is hardly ever standard due to difference of environment between companies. Techniques such as interviews, vulnerability scans and observation/analyses are steps undertaken by security auditor. Often the companies’ security policies and procedures need to be analysed not only to check if there is lack of consistency within those documents but also to base the analyses and mechanism of auditing on these policies. CAAT’s (Computer-Assigned audit Technologies) are utilities to generate system reports that store all the logs and configuration files and sometimes even monitor activities. I think that it’s very useful as the information can be very well formatted and display to an auditor without him going into specific directories/volumes or configuration files to get the information needed. Some of these tools actually have programmed patterns of for instance default configuration files which are being matched to the tested system configuration files and it flags the auditor when positive.

Considering auditor role as an investigator there are certain areas that are need to be checked for instance the way the passwords are generated or the way backups are stored often by asking all sorts of questions based on the auditors experience. I think the very important issue to observe is that some companies have got their own internal auditors/security consultant/officers which can help however to gain objective system audit an external auditor is a must. In many companies that is a way to check how the IT Department is developing and progressing. External auditor will produce the report on their achieved goals and aims for the next audit. That is normally the formal report produced few weeks after the audit takes place. Some institutions like Higher education or some government bodies have a law that impose to make sure that externals audits are up to date and consistently maintained.

John Edwards. (2008). The Essential Guide to Security Audits. Available: http://www.itsecurity.com/features/security-audit-essentials-042908/#comments.

Tuesday 2 August 2011

Java Hangman game with source code

Please include me in your references if you copy any part of the code.

User Guide:


Source Code:

package hangMAN;

import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;


/**
* @author Malkor13
* ispired by System of a Down mix albums playlist
*/
public class hangman2 {


//list of hidden words.

private List wordList = new ArrayList();

// list of labels

private List labelList = new ArrayList();

// The secret word.

private String hiddenWord;

// fiel for input.

private JTextField inputLetterField;

// Frame

private JFrame frame;

// panel to display the game

private JPanel gamePanel;

// panel to dispay the label

private JPanel labelPanel;

// panel to display the lives

private JPanel livesPanel;

// Panel for cathegory

private JPanel cathegoryPanel;
//Label for cathegory

private JLabel catLabel;


// index from list for keeping track of secret hidden word.


private int previousIndex;

// lives.

private int lives;

// Label for lives.

private JLabel livesLabel;

//Main method

public static void main(String[] args) {
hangman2 hangman = new hangman2();
hangman.addWords(); // add secret words to list
hangman.getWord(); // make secret word
hangman.display(); // display game
}


// List of the premiership teams to make it easier to guess

public void addWords() {
wordList.add("manchesterunited");
wordList.add("liverpool");
wordList.add("chelsea");
wordList.add("arsenal");
wordList.add("astonvilla");
wordList.add("everton");
wordList.add("fulham");
wordList.add("westham");
wordList.add("manchestercity");
wordList.add("tottenham");
wordList.add("wigan");
wordList.add("stoke");
wordList.add("bolton");
wordList.add("portsmouth");
wordList.add("blackburn");
wordList.add("hull");
wordList.add("newcastle");
wordList.add("middlesbourgh");
wordList.add("westbrom");


}
//method for random word
public void getWord() {
Random random = new Random();
int index = random.nextInt(wordList.size());
while (index == previousIndex) {
index = random.nextInt(wordList.size());
}
hiddenWord = wordList.get(index);
previousIndex = index;
}


// gui

public void display() {
frame = new JFrame("HaNgMaN");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(new GameBar());
gamePanel = new JPanel(new BorderLayout());
livesPanel = new JPanel();
lives = 6;
livesLabel = new JLabel(lives + " lives remaining");
livesPanel.add(livesLabel);
gamePanel.add(livesPanel, BorderLayout.WEST);
cathegoryPanel = new JPanel();
catLabel = new JLabel("Cathegory: Premiership Football Teams 2008/09");
cathegoryPanel.add(catLabel);
gamePanel.add(cathegoryPanel, BorderLayout.NORTH);


JPanel fieldPanel = new JPanel();
inputLetterField = new JTextField(1);
inputLetterField.addKeyListener(new LetterChecker());
fieldPanel.add(inputLetterField);
gamePanel.add(fieldPanel, BorderLayout.CENTER);

labelPanel = new JPanel();
setupLabels();
frame.add(gamePanel, BorderLayout.CENTER);

frame.setSize(300,150);
frame.setResizable(false);
frame.setVisible(true);
}

//lebel to display dashes
private void setupLabels() {
for (int i=0; i < hiddenWord.length(); i++) {
JLabel label = new JLabel("-");
labelList.add(label);
labelPanel.add(label);
}
gamePanel.add(labelPanel, BorderLayout.SOUTH);
}

//newgame method ,sets lives to 7 and refresh panels
private void newGame() {

lives = 6; // reset lives
livesLabel.setText(lives + " lives remaining");
livesPanel.validate(); // refresh lives panel
// remove all labels
for (JLabel label : labelList) {
labelPanel.remove(label);
}
labelPanel.validate(); // refresh label panel
gamePanel.remove(labelPanel); // remove label panel
gamePanel.validate(); // refresh game panel
labelList.clear();
getWord();
setupLabels();
frame.validate(); // refresh frame
}

//inner class for menu bar
private class GameBar extends JMenuBar {
private GameBar() {
super();
generateGameMenu();
}

//gui for menu
private void generateGameMenu() {
JMenu gameMenu = new JMenu("Game");
gameMenu.setMnemonic(KeyEvent.VK_G);
JMenuItem newGameItem = new JMenuItem(new GameAction());
newGameItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
InputEvent.ALT_DOWN_MASK)); //shortcut
gameMenu.add(newGameItem);
gameMenu.addSeparator();
JMenuItem exitItem = new JMenuItem(new ExitAction());
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
InputEvent.ALT_DOWN_MASK)); // shortcut ;)
gameMenu.add(exitItem);
add(gameMenu);
}

} // end inner class

//inner class for action
private class GameAction extends AbstractAction {
private GameAction() {
putValue(AbstractAction.NAME, "New");
putValue(AbstractAction.SHORT_DESCRIPTION, "New game");
putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_N);
}
//new game
@Override
public void actionPerformed(ActionEvent e) {
newGame();
}

} // end inner class
//inner class for another action
private class ExitAction extends AbstractAction {
private ExitAction() {
putValue(AbstractAction.NAME, "Exit");
putValue(AbstractAction.SHORT_DESCRIPTION, "Exit game");
putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_X);
}
//for exit
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}

} // end inner class


//checks user input

private class LetterChecker extends KeyAdapter {
private boolean isComplete() {
int length = 0;
for (JLabel label : labelList) {
if (label.getText().charAt(0) != '-') {
length++;
}
}
if (hiddenWord.length() != length) {
return false;
}
else {
return true;
}
}
//validate user inpit
@Override
public void keyTyped(KeyEvent e) {
char ch = e.getKeyChar(); // get input
// check if input is numeric
if (e.isAltDown() || e.isShiftDown() || Character.isDigit(ch)) {}
else {
char[] ary = new char[hiddenWord.length()];
ary = hiddenWord.toCharArray();
boolean noMatch = true; // assume incorrect input
for (int i=0; i < ary.length; i++) {
if (ch == ary[i]) {
// get label index
JLabel charLabel = labelList.get(i);
// update label
charLabel.setText(Character.toString(ch));
noMatch = false;
if (isComplete()) { // check if word is completed
//shows dialog
int option = JOptionPane.showConfirmDialog(null,
"Congratulations ! New game??",
"Gooooooooooooooooood!",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
if (option == JOptionPane.OK_OPTION) {
newGame();
}
}
}
}
if (noMatch) { // incorrect input
lives--; // decrement lives
// update lives label
livesLabel.setText(lives + " lives remaining");
livesPanel.validate(); // refresh lives panel
if (lives == 0) {
int option = JOptionPane.showConfirmDialog(null,
"Game over! New game?",
"Buuuuuuuuuu!",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
if (option == JOptionPane.OK_OPTION) {
newGame(); // restart game
}
}
else {
JOptionPane.showMessageDialog(null, "No match :-P",
"Wrong", JOptionPane.PLAIN_MESSAGE);
gamePanel.validate(); // refresh game panel
frame.validate(); // refresh window
}
}
inputLetterField.setText(""); // display only one letter
}
}

} // end inner class
}

Monday 1 August 2011

Flex emulating sh terminal

private function keyHandler(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.ENTER){
// variable to hold user input
var command:String = userInput.text;
// variable to read from output and keep history
var history:String = console.text;
// variables to create shell like enviroment
var root:String = "root@LB:~# ";
var rootchanged:String = "root@LB:";
var i:int = 0;
// cd command (for instance cd /home)
if (command.charAt(0) == "c" && command.charAt(1) == "d"){
var words:Array = command.split(" ");
var changedcurrent:String = words[1];
console.text = history + rootchanged + changedcurrent + "#" + "\n"}
else{
//arrays that holds possbile commands and output
known.push("pwd","ls","arp","help");
answer.push("/root" ,"filezilla3","192.168.25.254 either 00:50:56:f0:87:d2 eth1","pwd, ls, arp, help");
hint.push("help");
// loop through known commands
for (i=0; i if(userInput.text == known[i]){
//displaying output
console.text = history + root + userInput.text + "\n"+ answer[i] + "\n"
}}}}}

Primitive type is to be replaced by more object-oriented approach.