The word "foo" may be a corruption of F00 ('F'-zero-zero), which Data General Corp. used as a generic file example in its documentation in the '60's and '70s. Examples would refer to file F00, F01, etc.
However, it is unlikely that the above etymology is correct. There is some discussion at http://catb.org/~esr/jargon/html/F/foo.html.
FUBAR is a military acronym meaning "Fucked Up Beyond All Recognition". I always assumed the use of foo and bar as MetasyntacticVariables derived from this. That doesn't seem to be the case either.
FUBAR itself has also been suggested as drawing inspiration from German furchtbar ~= awful.